-->
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.  [ 2 posts ] 
Author Message
 Post subject: Saving 2 levels of parent-child relationship
PostPosted: Sun Feb 10, 2008 3:41 pm 
Newbie

Joined: Sun Feb 10, 2008 3:28 pm
Posts: 3
Hi, I am having the following problem domain classes:

Account, Group and Share (all entities)

The relationship between Account and Group is one-to-many
and between Group and Share is also one-to-many.

How can I, in a single session, add a Group to an existing Account and with a new Share associated to the Group?

If I do:

Code:
account = (Account) session.load(Account.class, new Long(id));

Group group = new Group();
group.set...
group.set...

Share share = new Share();
share.set...
share.set...

group.getShares().add(share);
share.setGroup(group);

account.getGroups().add(group);
group.setAccount(account);

session.flush();


This hangs after adding the share to the group's collection.
These one-to-many relationships are mapped with a Set (HashSet) and a cascade of "save-update".

If I do not add a share, the code works.

Any suggestion?

cheers


Top
 Profile  
 
 Post subject: Re: Saving 2 levels of parent-child relationship
PostPosted: Sun Feb 10, 2008 10:14 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
What do you mean it hangs? The group object at this point is not even a managed entity so hibernate is not doing anything here. What is the code for these entities?



Farzad-


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