mirror of https://github.com/apache/openjpa.git
OPENJPA-1242: fix cascade delete for 1-1 relation in an embeddable
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@803763 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6c2e3e2d03
commit
a488a122cf
|
@ -289,13 +289,17 @@ class SingleFieldManager
|
|||
* Dereference field values.
|
||||
*/
|
||||
public void dereferenceDependent() {
|
||||
delete(false, null);
|
||||
delete(false, null, true);
|
||||
}
|
||||
|
||||
private void delete(boolean immediate, OpCallbacks call) {
|
||||
delete(immediate, call, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete or dereference the stored field as necessary.
|
||||
*/
|
||||
private void delete(boolean immediate, OpCallbacks call) {
|
||||
private void delete(boolean immediate, OpCallbacks call, boolean deref) {
|
||||
if (objval == null)
|
||||
return;
|
||||
|
||||
|
@ -305,8 +309,8 @@ class SingleFieldManager
|
|||
// works on external value
|
||||
if ((immediate || fmd.isEmbeddedPC())
|
||||
&& fmd.getCascadeDelete() == ValueMetaData.CASCADE_IMMEDIATE) {
|
||||
if (fmd.isEmbeddedPC())
|
||||
dereferenceEmbedDependent(_sm);
|
||||
if (fmd.isEmbeddedPC() && deref)
|
||||
dereferenceEmbedDependent(_broker.getStateManagerImpl(objval, false));
|
||||
delete(fmd, objval, call);
|
||||
}
|
||||
else if (fmd.getCascadeDelete() == ValueMetaData.CASCADE_AUTO)
|
||||
|
|
|
@ -1357,7 +1357,7 @@ public class StateManagerImpl
|
|||
}
|
||||
|
||||
public boolean getDereferencedEmbedDependent() {
|
||||
return ((_flags |= FLAG_EMBED_DEREF) == 0 ? false : true);
|
||||
return ((_flags & FLAG_EMBED_DEREF) == 0 ? false : true);
|
||||
}
|
||||
|
||||
///////////
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.apache.openjpa.persistence.embed;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
|
@ -26,7 +27,7 @@ public class Embed_ToOne {
|
|||
protected String name1;
|
||||
protected String name2;
|
||||
protected String name3;
|
||||
@OneToOne
|
||||
@OneToOne(cascade=CascadeType.ALL)
|
||||
protected EntityB1 b;
|
||||
|
||||
public String getName1() {
|
||||
|
|
|
@ -825,6 +825,12 @@ public class TestEmbeddable extends SingleEMFTestCase {
|
|||
EntityManager em = emf.createEntityManager();
|
||||
EntityA_Embed_ToOne a = em.find(EntityA_Embed_ToOne.class, ID);
|
||||
checkEntityA_Embed_ToOne(a);
|
||||
em.getTransaction().begin();
|
||||
em.remove(a);
|
||||
em.getTransaction().commit();
|
||||
//delete cascade
|
||||
EntityB1 b = em.find(EntityB1.class, ID);
|
||||
assertNull(b);
|
||||
em.close();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue