-->
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: Parent Child question
PostPosted: Mon Dec 24, 2007 1:20 pm 
Newbie

Joined: Mon Dec 24, 2007 1:05 pm
Posts: 2
I have a general question on Parent child mapping, two following objects :
(Nhibernate 1.2)

Parent object mapping
<class name="BaseCustomer, com.xxx.Business" table="CUSTOMER.CUSTOMER">
<id name="Id" column="Customerid" type="Int64" unsaved-value="0">
<generator class="sequence">
<param name="sequence">SEQ_CUSTOMER</param>
</generator>
</id>
<property name="Firstname" column="Firstname" type="String" />
<property name="Lastname" column="Lastname" type="String" />
<bag name="HistoryNotes" cascade="all" inverse="true" >
<key column="Customerid" />
<one-to-many class="Customerhistory, com.xxx.Business" />
</bag>
</class>

Child object mapping
<class name="Customerhistory, com.xxx.Business" table="CUSTOMER.CUSTOMERHISTORY">
<id name="Id" column="Customerhistoryid" type="Int64" unsaved-value="0">
<generator class="sequence">
<param name="sequence">seq_customerhistory</param>
</generator>
</id>
<property name="Description" column="Description" type="String" />
<property name="Systemnote" column="Systemnote" type="Int64" />

<!-- bidirectional mapping to the contact-->
<many-to-one name="ParentBaseCustomer"
class="BaseCustomer, com.xxx.Business"
column="Customerid" not-null="true"/>
</class>


If I'm creating a new parent object and attaching new child objects I'm getting an error when saving . The error is because of the constraint between the child and the parent (in the time I added the child objects the parent didn't had a identifier).
Should I save/flush the parent object before I'm saving the child object ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 12:08 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
When creating a new parent and child in the same session, save the parent before associating the child. You don't need to flush.

AFAIK this is not supposed to be necessary, and is a bug ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 12:11 pm 
Newbie

Joined: Mon Dec 24, 2007 1:05 pm
Posts: 2
It is working for an existing item , so i might be a bug
If it's a bug , should I submit it any where ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 12:26 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
You can submit bugs to the NHibernate JIRA:
http://www.hibernate.org/217.html


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.