Hi,
I'm trying to implement an inheritance with a discriminator. And I want to have a set of the classes in such an inheritance tree.
Class Parent {} Class Child1 extends Parent {} Class Child2 extends Parent {}
Class Scheme { Set<Child1> data; } I would like to have in a Scheme class a set of Child1.
And when I'd like to save the Scheme object with a link to a Child1 I have the following SQL log: Hibernate: select gen_id( GEN_SCHEME_ID, 1 ) from RDB$DATABASE Hibernate: select gen_id( GEN_PARENT_ID, 1 ) from RDB$DATABASE Hibernate: insert into T_SCHEME (title, description, id) values (?, ?, ?, ?) Hibernate: insert into T_PARENT (title, description, SCHEME_ID, discriminator, id) values (?, ?, ?, 'child1', ?) Hibernate: insert into T_CHILD1 (..........) values (?, ?, ?, ?, ?, ?, ?) Hibernate: update T_PARENT set SCHEME_ID=? where id=?
I'm confused why SCHEME_ID is inserting in T_PARENT table?! I want it to be in CHILD1 table! Is it possible or not?
Thank you in advance.
The sample XML-mapping is below:
<hibernate-mapping> <class name="Scheme" table="T_SCHEME"> <id name="id"> <generator class="native"> <param name="sequence">GEN_SCHEME_ID</param> </generator> </id>
.......
<set name="child" cascade="all" lazy="false"> <key column="SCHEME_ID" not-null="true"/> <one-to-many class="Child1"/> </set> </class> </hibernate-mapping>
<hibernate-mapping> <class name="Parent" table="T_DATA"> <id name="id"> <generator class="native"> <param name="sequence">GEN_USER_ID</param> </generator> </id>
<discriminator column="discriminator" type="string"/>
.........
<subclass name="Child1" discriminator-value="child1"> <join table="T_CHILD1"> <key column="ID"/> .... </join> </subclass>
<subclass name="Child2" discriminator-value="child2"> <join table="T_CHILD2"> <key column="ID"/> .... </join> </subclass> </class> </hibernate-mapping>
|