openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1043597 - in /openjpa/branches/2.0.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
Date Wed, 08 Dec 2010 18:49:17 GMT
Author: jgrassel
Date: Wed Dec  8 18:49:17 2010
New Revision: 1043597

URL: http://svn.apache.org/viewvc?rev=1043597&view=rev
Log:
OPENJPA-1890: Fix NPE when an embeddable is set to a managed entity more then once, merged
from Fay's changes for trunk

Modified:
    openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java

Modified: openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java?rev=1043597&r1=1043596&r2=1043597&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
(original)
+++ openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
Wed Dec  8 18:49:17 2010
@@ -309,8 +309,12 @@ class SingleFieldManager
             // works on external value
             if ((immediate || fmd.isEmbeddedPC())
                 && fmd.getCascadeDelete() == ValueMetaData.CASCADE_IMMEDIATE) {
-                if (fmd.isEmbeddedPC() && deref)
-                    dereferenceEmbedDependent(_broker.getStateManagerImpl(objval, false));
+                if (fmd.isEmbeddedPC() && deref) {
+                    StateManagerImpl sm = _broker.getStateManagerImpl(objval, false);
+                    if (sm != null) {
+                        dereferenceEmbedDependent(sm);
+                    }
+                }
                 delete(fmd, objval, call);
             }
             else if (fmd.getCascadeDelete() == ValueMetaData.CASCADE_AUTO)

Modified: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java?rev=1043597&r1=1043596&r2=1043597&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
(original)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
Wed Dec  8 18:49:17 2010
@@ -190,6 +190,20 @@ public class TestEmbeddable extends SQLL
         em.close();
     }
 
+    /**
+     * Test for OJ-1890.
+     */
+    public void testSettingEmbeddableMultipleTimesOnManagedEntity() {
+        createEntityA_Embed();
+        EntityManager em = emf.createEntityManager();
+        EntityA_Embed ee = em.find(EntityA_Embed.class, ID);
+        Embed embed = createEmbed(ID, 0);
+        ee.setEmbed(embed);
+        Embed embed1 = createEmbed(ID, 1);
+        ee.setEmbed(embed1);
+        em.close();
+    }
+    
     public void testEntityA_Embed_Coll_Map() {
         queryEntityA_Embed_Coll_Map();
     }
@@ -638,12 +652,12 @@ public class TestEmbeddable extends SQLL
         a.setId(id);
         a.setName("a" + id);
         a.setAge(id);
-        Embed_Embed embed = createEmbed_Embed(em, id, 0);
+        Embed_Embed embed = createEmbed_Embed(id, 0);
         a.setEmbed(embed);
         em.persist(a);
     }
 
-    public Embed_Embed createEmbed_Embed(EntityManager em, int id, int idx) {
+    public Embed_Embed createEmbed_Embed(int id, int idx) {
         Embed_Embed embed = new Embed_Embed();
         embed.setIntVal1(id * 100 + idx * 10 + 1);
         embed.setIntVal2(id * 100 + idx * 10 + 2);
@@ -653,6 +667,26 @@ public class TestEmbeddable extends SQLL
         return embed;
     }
 
+    public void createEntityA_Embed() {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        createEntityA_Embed(em, ID);
+        tran.begin();
+        em.flush();
+        tran.commit();
+        em.close();
+    }
+
+    public void createEntityA_Embed(EntityManager em, int id) {
+        EntityA_Embed a = new EntityA_Embed();
+        a.setId(id);
+        a.setName("a" + id);
+        a.setAge(id);
+        Embed embed = createEmbed(id, 0);
+        a.setEmbed(embed);
+        em.persist(a);
+    }
+        
     public Embed createEmbed(int id, int idx) {
         Embed embed = new Embed();
         embed.setIntVal1(id * 100 + idx * 10 + 4);
@@ -680,7 +714,7 @@ public class TestEmbeddable extends SQLL
         a.setName("a" + id);
         a.setAge(id);
         for (int i = 0; i < numEmbeddables; i++) {
-            Embed_Embed embed = createEmbed_Embed(em, id, i);
+            Embed_Embed embed = createEmbed_Embed(id, i);
             a.addEmbed(embed);
         }
         em.persist(a);
@@ -1066,7 +1100,7 @@ public class TestEmbeddable extends SQLL
         
         em.clear();
         em.getTransaction().begin();
-        Embed_Embed embed = createEmbed_Embed(em, ID, 100);
+        Embed_Embed embed = createEmbed_Embed(ID, 100);
         a.addEmbed(embed);
         em.merge(a);
         em.getTransaction().commit();
@@ -2849,9 +2883,9 @@ public class TestEmbeddable extends SQLL
         a.addCreditRating(EntityA_Embed_Complex.CreditRating.POOR);
         a.addTimestamp(new Timestamp(cal.getTimeInMillis()));
         a.addLob("lob_0");
-        a.setEmbed(createEmbed_Embed(em, numEmbeddables, 0));
+        a.setEmbed(createEmbed_Embed(numEmbeddables, 0));
         for (int i = 0; i < numEmbeddables; i++) {
-            Embed_Embed embed = createEmbed_Embed(em, id, i);
+            Embed_Embed embed = createEmbed_Embed(id, i);
             a.addEmbed(embed);
         }
         for (int i = 0; i < numEmbeddables; i++) {



Mime
View raw message