hibernate version:latest
Hello all,
I have 2 mapping files -> standard parent child r/s but in the child mapping file there are multiple joined subclasses and the parent is the parent of these multiple subclasses. now obviously, these multiple child sub classes will need a foreign key to the parent class so i put the <many-to-one> to the parent at the top of the main child class:
<class name="mainChild" ...>
<many-to-one name="parent" class="Parent" column="parent_id"/>
<joined-subclass name="childSubClass1"...></joined-subclass>
<joined-subclass name="childSubClass2"...></joined-subclass>
<joined-subclass name="childSubClass3"...></joined-subclass>
....
</class>
The parent class file is something like this:
<class name="Parent" ...>
....
<set name="childSubClass1" cascade="all" lazy="true" inverse="true">
<key column="parent_id"/>
<one-to-many class="childSubClass1"/>
</set>
<set name="childSubClass2" cascade="all" lazy="true" inverse="true">
<key column="parent_id"/>
<one-to-many class="childSubClass2"/>
</set>
......
</class>
When i hibernate create the tables in the database, i can see that parent_id can be found in the table of mainChild, however, i also see that
childSubClass1 and childSubClass2 also have a parent_id field
now the problem is that when i add , say,childSubClass1 to parent and parent to childSubClass1 and cascade save the parent, the parent_id is correctly saved to the parent_id of mainChild but nothing gets saved to the parent_id of childSubClass1, can anyone tell me what is wrong? and when i search for instances of childSubClass1 with a parent_id of 1, i dont get any results becos parent_id is saved in the mainChild table and not in
childSubClass1 table. What gives?
Best Regards
|