openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1535379 - in /openjpa/branches/2.3.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/
Date Thu, 24 Oct 2013 13:42:42 GMT
Author: curtisr7
Date: Thu Oct 24 13:42:42 2013
New Revision: 1535379

URL: http://svn.apache.org/r1535379
Log:
OPENJPA-2443 : Fix SingleFieldManager to not check for null values for IDENTITY generated
fields when flushing.

Modified:
    openjpa/branches/2.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
    openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/AutoIncrementEntity.java
    openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/TestAutoIncrement.java

Modified: openjpa/branches/2.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java?rev=1535379&r1=1535378&r2=1535379&view=diff
==============================================================================
--- openjpa/branches/2.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
(original)
+++ openjpa/branches/2.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
Thu Oct 24 13:42:42 2013
@@ -30,12 +30,12 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.TimeZone;
 
-import org.apache.openjpa.conf.Compatibility;
 import org.apache.openjpa.enhance.PersistenceCapable;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.meta.JavaTypes;
 import org.apache.openjpa.meta.ValueMetaData;
+import org.apache.openjpa.meta.ValueStrategies;
 import org.apache.openjpa.util.ChangeTracker;
 import org.apache.openjpa.util.Exceptions;
 import org.apache.openjpa.util.ImplHelper;
@@ -557,15 +557,16 @@ class SingleFieldManager extends Transfe
     /**
      * Helper method to perform pre flush actions on the current object.
      */
-    private boolean preFlush(FieldMetaData fmd, boolean logical, 
-        OpCallbacks call) {
+    private boolean preFlush(FieldMetaData fmd, boolean logical, OpCallbacks call) {
         // check for illegal nulls
         if (objval == null) {
-            if (fmd.getNullValue() == FieldMetaData.NULL_EXCEPTION
-                || fmd.getDeclaredTypeCode() == JavaTypes.OID)
-                throw new InvalidStateException(_loc.get("null-value",
-                    fmd.getName(), _sm.getManagedInstance())).
-                    setFatal(true);
+            // If we have an AUTOASSIGN strategy that means that we have a field that is
GenerationType.IDENTITY so
+            // skip checking to see if the value is null as it will get assigned later in
flush processing. 
+            if (fmd.getValueStrategy() != ValueStrategies.AUTOASSIGN) {
+                if (fmd.getNullValue() == FieldMetaData.NULL_EXCEPTION || fmd.getDeclaredTypeCode()
== JavaTypes.OID)
+                    throw new InvalidStateException(_loc.get("null-value", fmd.getName(),
_sm.getManagedInstance()))
+                        .setFatal(true);
+            }
             return false;
         }
 

Modified: openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/AutoIncrementEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/AutoIncrementEntity.java?rev=1535379&r1=1535378&r2=1535379&view=diff
==============================================================================
--- openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/AutoIncrementEntity.java
(original)
+++ openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/AutoIncrementEntity.java
Thu Oct 24 13:42:42 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.openjpa.persistence.jdbc.auto;
 
+import javax.persistence.Basic;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
@@ -27,16 +28,17 @@ import javax.persistence.Version;
 @Entity
 public class AutoIncrementEntity {
     @Id
-    @GeneratedValue(strategy=GenerationType.IDENTITY)
-    public int id;
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Basic(optional = false)
+    Integer id;
 
     @Version
     int version;
-    
+
     public String somethingElse;
-    
-    public int getId(){
+
+    public Integer getId() {
         return id;
     }
-    
+
 }

Modified: openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/TestAutoIncrement.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/TestAutoIncrement.java?rev=1535379&r1=1535378&r2=1535379&view=diff
==============================================================================
--- openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/TestAutoIncrement.java
(original)
+++ openjpa/branches/2.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/TestAutoIncrement.java
Thu Oct 24 13:42:42 2013
@@ -49,10 +49,24 @@ public class TestAutoIncrement extends S
         AutoIncrementEntity e1 = em.find(AutoIncrementEntity.class, 0);
         assertNotNull(e1);
         AutoIncrementEntity e2 = new AutoIncrementEntity();
-        assertEquals(0, e2.getId());
+        assertEquals(null, e2.getId());
         em.persist(e2);
         em.getTransaction().commit();
-        assertNotEquals(0, e2.getId());
+        assertNotEquals(null, e2.getId());
+    }
+    
+    public void testMergeNewEntity() {
+        if (disabled) {
+            return;
+        }
+        AutoIncrementEntity e2 = new AutoIncrementEntity();
+        
+        em.getTransaction().begin();
+        AutoIncrementEntity e3 = em.merge(e2);
+        em.getTransaction().commit();
+        
+        assertNotNull(e3);
+        
     }
     
     /**



Mime
View raw message