-->
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.  [ 4 posts ] 
Author Message
 Post subject: Inherited property not saved at all Strange!!!
PostPosted: Sun Aug 29, 2004 9:59 pm 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 11:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You use <key>, not <many-to-one> to define the FK to the superclass. Check the DTD.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 12:35 am 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
Hello Gavin,

I am sorry but i dont think i understand what you mean. Perhaps i didnt state properly in my mapping snippet below:

<class name="mainChild" ...>

<many-to-one name="parent" class="Parent" column="parent_id"/>

<joined-subclass name="childSubClass1"...><key column="id"/>...</joined-subclass>
<joined-subclass name="childSubClass2"...><key column="id"/>...</joined-subclass>
<joined-subclass name="childSubClass3"...><key column="id"/>...</joined-subclass>

....
</class>


Even with the <key>, the problem still persists( if thats what you mean by "You use <key>, not <many-to-one> to define the FK to the superclass".

Becos the <many-to-one> is defined in the superclass(mainChild), the parent_id saved in the superclass but not in the subclass cos i think the parent class is pointing to the subclass(eg.childSubClass1) instead of the superclass (mainClass) but isnt that how it is supposed to be?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 5:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Have a look at some examples in the documentation.


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

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.