-->
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.  [ 3 posts ] 
Author Message
 Post subject: one to many mapping
PostPosted: Tue Aug 10, 2010 6:54 pm 
Newbie

Joined: Thu Jul 29, 2010 5:24 pm
Posts: 5
I have an hbm.xml file which has one-to-many mapping to another java class.

<class name="com.XYZ" table="XYZ" >
<id name="pk" type="java.lang.Integer">
<column name="PK" />
<generator class="identity" />
</id>
<property name="username" type="string">
<column name="USERNAME" length="45" not-null="true" />
</property>
<property name="pwd" type="string">
<column name="PWD" length="45" not-null="true" />
</property>
<set name="Products" inverse="true" lazy="true" table="PRODUCTS" fetch="select">
<key>
<column name="FK_XYZ_PK" not-null="true" />
</key>
<one-to-many class="com.Product" />
</set>
</class>


If I do a session.save(xyz) //if xyz is the instance of com.XYZ

and if xyz contains a set of products, then if I do a save on xyz will products also be saved in PRODUCTS table.

When I tried saving xyz products were not saved in PRODUCTS table.

Can any one please help me with it , so that when I save XYZ , it corresponding one to many relationship table is also saved.

Thanks in advance.

Amy


Top
 Profile  
 
 Post subject: Re: one to many mapping
PostPosted: Wed Aug 11, 2010 2:22 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Seems like you need to enable cascade on the one-to-many. Eg.

Code:
<set name="Products" .... cascade="save-update">


For more information about cascading see:
http://docs.jboss.org/hibernate/stable/ ... ns-mapping

and for some code examples: http://docs.jboss.org/hibernate/stable/ ... d-cascades


Top
 Profile  
 
 Post subject: Re: one to many mapping
PostPosted: Wed Aug 11, 2010 11:37 am 
Newbie

Joined: Thu Jul 29, 2010 5:24 pm
Posts: 5
Thanks nordborg for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.