-->
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.  [ 7 posts ] 
Author Message
 Post subject: CAN I INSER BOTH PARENT AND CHILD using single save(parent)?
PostPosted: Fri Aug 19, 2005 2:28 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Hi,
Can I save parent and child details using single save?

For ex, if I have Employee and Address objects in one-to-many form, is it possible for me to save one employee with 3 addresses in a single
session.save(employee), after having set employee.setEmployees() Collection????

Or do I need to save parent first and then children????

Please advise???


Top
 Profile  
 
 Post subject: CAN I INSERT BOTH PARENT AND CHILD USING Single Save()???
PostPosted: Fri Aug 19, 2005 2:29 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
arumugam_kasi wrote:
Hi,
Can I save parent and child details using single save?

For ex, if I have Employee and Address objects in one-to-many form, is it possible for me to save one employee with 3 addresses in a single
session.save(employee), after having set employee.setEmployees() Collection????

Or do I need to save parent first and then children????

Please advise???


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 3:08 am 
Newbie

Joined: Wed Aug 17, 2005 5:27 am
Posts: 3
You can set the parameter cascade in your mapping file (for the collection) to save-update.

eg

<list name="address" table="address" cascade="save-update" .......>

you can also set this to

all|none|save-update|delete|all-delete-orphan

I hope this helps


Top
 Profile  
 
 Post subject: Let me know if you succeded
PostPosted: Fri Aug 19, 2005 9:59 am 
Newbie

Joined: Tue Aug 02, 2005 1:40 pm
Posts: 16
Location: US
Hello arumugam_kasi;

I did try the cascade property and always Hibernate tends to update the child. This happens specifically when i mentione one-to-many relating in the collection i.e. in the bag / set / map

instend of one-to-many when i specify the child table with composit-element then hibernate is inserting into the child table

eg:
[code]
<bag name="x" table="x" cascade="all">
<key >
<column name="ID" />
</key>
<composite-element class="y">
<property name="xyz" type="integer" column="xyz"/>
<property name="abc" type="integer" column="abc"/>
<property name="efg" type="integer" column="efg"/>
</composite-element>
</bag>

the above would do an insert to child

instead if you have

[code]
<bag name="x" table="x" cascade="all">
<key >
<column name="ID" />
</key>
<one-to-many class="y" />
</bag>
this is doing an update.

well thatz the way it is working for me. I am breaking my head to solve the second case to insert. Let me know if both work fine with you.

Regards

Rajeshwar Rao[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:11 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
add inverse=true in your collection.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:18 am 
Newbie

Joined: Tue Aug 02, 2005 1:40 pm
Posts: 16
Location: US
I did that too it did not help. I am trying the method suggested is some other forum topic where in i would be introducing an add method th my POJO so that hibernate understands it as an insert.

Anyways thanks for your reply. If you have any other suggestion then do let me know i have just started applying the add suggestion

Rajesh


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:48 am 
Newbie

Joined: Tue Aug 02, 2005 1:40 pm
Posts: 16
Location: US
I tried the add method in POJO this does not help too .. It still gives me update statements


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