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.