-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Inheritance with invalid foreign key table
PostPosted: Wed Mar 31, 2010 3:04 pm 
Newbie

Joined: Wed Mar 31, 2010 2:41 pm
Posts: 1
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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.