openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1084351 - in /openjpa/branches/2.1.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/
Date Tue, 22 Mar 2011 21:08:39 GMT
Author: curtisr7
Date: Tue Mar 22 21:08:39 2011
New Revision: 1084351

URL: http://svn.apache.org/viewvc?rev=1084351&view=rev
Log:
OPENJPA-1944: Properly handle a null version field.

Modified:
    openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/AnnoTest1.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestVersion.java

Modified: openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?rev=1084351&r1=1084350&r2=1084351&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Tue Mar 22 21:08:39 2011
@@ -131,7 +131,7 @@ public class StateManagerImpl
     // the managing persistence manager and lifecycle state
     private transient BrokerImpl _broker; // this is serialized specially
     private PCState _state = PCState.TRANSIENT;
-
+    
     // the current and last loaded version indicators, and the lock object
     private Object _version = null;
     private Object _loadVersion = null;
@@ -3069,7 +3069,8 @@ public class StateManagerImpl
             // always be set after the first state load or set (which is why
             // we do this even if no fields were loaded -- could be that this
             // method is being called after a field is set)
-            if (_loadVersion == null && (_meta == null || _meta.getVersionField()
!= null)) {
+            FieldMetaData versionMeta = _meta !=null ? _meta.getVersionField() : null;
+            if (_loadVersion == null && (versionMeta != null && !_loaded.get(versionMeta.getIndex())))
{
                 syncVersion(sdata);
                 ret = ret || _loadVersion != null;
             }

Modified: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/AnnoTest1.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/AnnoTest1.java?rev=1084351&r1=1084350&r2=1084351&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/AnnoTest1.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/AnnoTest1.java
Tue Mar 22 21:08:39 2011
@@ -41,7 +41,7 @@ public class AnnoTest1 {
 
     @Version
     @Column(name = "ANNOVER")
-    protected int version;
+    protected Integer version;
 
     @Basic
     protected int basic;

Modified: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestVersion.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestVersion.java?rev=1084351&r1=1084350&r2=1084351&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestVersion.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestVersion.java
Tue Mar 22 21:08:39 2011
@@ -34,7 +34,9 @@ public class TestVersion extends SingleE
 
     public void setUp() {
         setUp(AnnoTest1.class, AnnoTest2.class, AnnoTest3.class, Flat1.class,
-            EmbedOwner.class, EmbedValue.class, CLEAR_TABLES);
+            EmbedOwner.class, EmbedValue.class, CLEAR_TABLES
+            , "openjpa.Log","SQL=trace","openjpa.ConnectionFactoryProperties","printParameters=true"
   
+        );
 
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
@@ -192,4 +194,38 @@ public class TestVersion extends SingleE
             cls.getVersion().getStrategy());
         assertEquals(1, cls.getVersion().getColumns().length);
     }
+    
+    public void testNullInitialVersion() {
+        EntityManager em = emf.createEntityManager();
+        EntityManager em2 = emf.createEntityManager();
+        try {
+            AnnoTest1 e = new AnnoTest1(System.currentTimeMillis());
+            em.getTransaction().begin();
+            em.persist(e);
+            em.createQuery("UPDATE AnnoTest1 a SET a.version=null where a.pk=:pk").setParameter("pk",
e.getPk())
+                .executeUpdate();
+            em.getTransaction().commit();
+            em.close();
+             em = emf.createEntityManager();
+            
+            em.getTransaction().begin();
+            em2.getTransaction().begin();
+            
+            AnnoTest1 e2 = em2.find(AnnoTest1.class, e.getPk());
+            e = em.find(AnnoTest1.class, e.getPk());
+            
+            e.setBasic(1);
+            em.getTransaction().commit();
+
+            e2 = em2.find(AnnoTest1.class, e.getPk());
+            em2.refresh(e2);
+
+            assertEquals(1, e2.getBasic());
+        } finally {
+            if (em.getTransaction().isActive()) {
+                em.getTransaction().rollback();
+            }
+            em.close();
+        }
+    }
 }



Mime
View raw message