Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] merge with bidirectional relationship

You are responsible for maintain bi-directional relationships, even with the
merge.

When setting B's as to null, you also need to set each A's b to null (and
merge it) (unless you use orphan removal and want the As deleted).



Cronemberger, Constantino wrote:
> 
> Hi,
> 
> I have now tried to specify CascadeType.MERGE on both sides of the
> relationship and I still have the same issue.
> 
> Regards,
>    Constantino
> 
> ________________________________
> From: Cronemberger, Constantino
> Sent: 30 June 2011 13:09
> To: eclipselink-users@xxxxxxxxxxx
> Subject: 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
> 
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance 
-- 
View this message in context: http://old.nabble.com/merge-with-bidirectional-relationship-tp31964535p32107924.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top