[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] merge with bidirectional relationship
|
Hi,
I am dealing with the following issue that I don't know if it is a bug or if JPA spec does not say anything about this scenario, in which case, it is going to be implementation specific.
One important thing: I am using annotations in attributes, so EclipseLink will not use getters and/or setters, only the application code.
I have a bidirectional relationship between A and B where B has a set of As and A has only one B. In this case the owning side is A.
I create an instance of A and B and assign B to A. I also add A to B collection of As.
Then in a new transaction, I get a detached B, call setAs(null) on B and try to call em.merge(B).
The result is that B has an empty collection of As, but A still points to B.
I remember that in JPA spec they say that the developer is responsible for keeping the synchronization of bidirectional relationships, but I was considering this would be valid only when the developer is doing an operation in the relationship.
In this case I think EclipseLink is doing the change, so my guess is that EclipseLink should also update the other side of the relationship.
Any ideas on how I can fix this? My simplest and easiest idea is to just not use merge anymore. A more complex idea would be to save the relationships before EclipseLink merges the entity and then merge the relationships manually to make sure they are in sync.
Thanks,
Constantino
Attachment:
clear[1].gif
Description: clear[1].gif