Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] JPA bidirectional @OneToOne and cascade merge

Hi,

I asked this on Stackoverflow, I wonder if you could have some clue?

http://stackoverflow.com/questions/15438040/jpa-bidirectional-onetoone-and-cascade-merge

If I have those two entities:

@Entity class A { 
    @OneToOne(cascade = CascadeType.MERGE, mappedBy = "a") B b; 
    //getters+setters
}
@Entity class B { 
    @OneToOne(cascade = CascadeType.MERGE) A a; 
    //getters+setters
}

Does the JPA specification guarantee this?

A a = new A();
B b = new B();
a.setB(b);
b.setA(a);
A managedA = entityManager.me
rge(a);
// after commit, managedA will have a reference to a managed B which JPA implementation will link to managedA instead of original unmanaged A
Assert.assertTrue(managedA.getB().getA() == managedA);

My understanding is that it works (at least with latest EclipseLink, at least sometimes), but that the spec doesn't guarantee that.

Counter-examples / spec excerpts welcome :-)



Back to the top