java - Map hibernate many-to-one with the foreign key in subclass joined table -
i'm mapping entities using hibernate 3 project , explained i've got kind of this:
student
entity (tstudent table)universitystudent
entity (tuniversitystudent table)university
entity (tuniversity table)
universitystudent
extends student
, has own attributes, university itself, foreign key tuniversitystudent table. mapped subclass student
class, using discriminator field:
<class name="mycompany.student" table="tstudent" discriminator-value="basic"> <id name="id" column="id" type="integer"> <generator class="native" /> </id> <discriminator column="type" /> <property name="name" column="name" /> <property name="surname" column="surname" /> <property name="phonenumber" column="phone_number" /> <subclass discriminator-value="university" name="mycompany.universitystudent"> <join table="tuniversitystudent"> <key column="id_student" /> <many-to-one name="university" class="mycompany.university"> <column name="id_university" /> </many-to-one> </join> </subclass> </class>
well, want have set
collection universitystudent
entities each university
. map that:
<class name="mycompany.university" table="tuniversity"> <id name="id" column="id" type="integer"> <generator class="native" /> </id> <property name="name" column="name" /> <set name="universitystudents" table="tuniversitystudent"> <key> <column name="id_university" /> </key> <one-to-many class="mycompany.universitystudent" /> </set> </class>
my problem comes when want load university
object, hibernate complains id_university
doesn't exist in tstudent table. checked generated sql query , tries load tstudent.
unknown column 'student0_.id_university' in 'field list'
it seems it's recognizing subclass of basic student
, tries join collection using field in parent table, field in child table, because university students can have university assigned.
i tried workaround seems work it's not valid me, that's mapping universitystudent
joined-subclass
instead of subclass
join inside:
<joined-subclass name="mycompany.universitystudent" table="tuniversitystudent"> <key column="id_student" /> <many-to-one name="university" class="mycompany.university"> <column name="id_university" /> </many-to-one> </joined-subclass>
however, i'm interested in keeping subclass discriminator value. idea?
i checked out resources , got bug: https://hibernate.atlassian.net/browse/hhh-1015, looks absolutely compatible case. checkout this old question well, again similar case.
firstly read definition of table per sublass given hibernate (i know, version 3.3 couldn't find same source hibernate 4): joined-subclass
seems (to me) custom implementation of subclass using discriminator
provided hibernate , reason stay away usage. however, know, mappings table per sublass , table per subclass using discriminator should equivalent, that's why believe bug pointed out still open.
if have time , will, can try use jpa provider , check if still run in same issue. jpa 2.0 specifications thing, provider implementation another! run bug (related @idclass
) forced me try eclipselink , configuration not working hibernate right eclipse link
Comments
Post a Comment