-->
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: associations between detached entities.
PostPosted: Tue Mar 27, 2007 3:01 pm 
Newbie

Joined: Tue Mar 27, 2007 2:37 pm
Posts: 2
Hi!

Using Hibernate3+EntityManager(for every HTTP query, a new EntityManager instance is created)

My problem is basically the same described by someone here:
http://forum.java.sun.com/thread.jspa?t ... &tstart=90

To sum up:
I've got entity A and B. There is a many-to-many relationship between them (B is the owning side, A is the inverse!)

At the beginning of my UI code, I start out with a detached A instance, which has a list of associated B instances (also detached). In the UI, the user has the possibility to remove some B instances associated to A, and also add new ones, which were not previously associated.

If I call merge() on A, A's list of Bs are not updated in the database. This comes as no surprise since A is the inverse side.

My question is, how to solve this?

I see two possibilities:

1. In my business method, I get the detached A as a parameter. I look up a managed version of the detached A instance, and compere its list of Bs to the List of Bs in the detached A copy. According to the comparison, I add the added ones, remove the removed ones (also do this on the B side, of course).

2. My business method gets the detached A copy and a list of Bs removed from the detached A's list of Bs. I merge both the detached A and the Bs which are removed from the association.

3. any other idea?

I'd be interested in Your best practices regarding this problem.

Thank you & best regards.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 2:42 pm 
Newbie

Joined: Tue Mar 27, 2007 2:37 pm
Posts: 2
what I did was to find() the manged copies of the detached objects, rearranged the relationship according to my needs and then did a merge(). However, I'd still be curious of what you think of what is the best practice for the above..


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.