openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1484300 - in /openjpa/branches/2.1.x: ./ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jd...
Date Sun, 19 May 2013 15:44:19 GMT
Author: hthomann
Date: Sun May 19 15:44:19 2013
New Revision: 1484300

URL: http://svn.apache.org/r1484300
Log:
OPENJPA-2373: MapsId in a Child entity to a Parent entity using auto-assigned identity fails
with duplicte INSERT SQL - back ported to 2.1.x Pinaki Poddar's trunk changes.

Added:
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/apps/Part.java
      - copied unchanged from r1484136, openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/apps/Part.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/apps/PartPK.java
      - copied unchanged from r1484136, openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/apps/PartPK.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/apps/Shirt.java
      - copied unchanged from r1484136, openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/apps/Shirt.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/apps/Textile.java
      - copied unchanged from r1484136, openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/apps/Textile.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/apps/TextilePK.java
      - copied unchanged from r1484136, openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/apps/TextilePK.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/apps/Trousers.java
      - copied unchanged from r1484136, openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/apps/Trousers.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/TestMapsIdWithAutoGeneratedKey.java
      - copied unchanged from r1484287, openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/TestMapsIdWithAutoGeneratedKey.java
Modified:
    openjpa/branches/2.1.x/   (props changed)
    openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
    openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java
    openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java
    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/inheritance/jointable/onetomany/
  (props changed)

Propchange: openjpa/branches/2.1.x/
------------------------------------------------------------------------------
  Merged /openjpa/branches/2.0.x:r1484136,1484287
  Merged /openjpa/trunk:r1469646,1469649,1469652

Modified: openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java?rev=1484300&r1=1484299&r2=1484300&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
(original)
+++ openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
Sun May 19 15:44:19 2013
@@ -57,6 +57,7 @@ import org.apache.openjpa.jdbc.sql.Selec
 import org.apache.openjpa.jdbc.sql.Union;
 import org.apache.openjpa.kernel.LockManager;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.kernel.StateManagerImpl;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
@@ -268,13 +269,26 @@ public class RelationFieldStrategy
         throws SQLException {
         if (field.getMappedBy() != null)
             return;
-
+        Row row = null;
         OpenJPAStateManager rel = RelationStrategies.getStateManager
             (sm.fetchObjectField(field.getIndex()), store.getContext());
-        if (field.getJoinDirection() == field.JOIN_INVERSE)
+        // Checks if the field being inserted is a MapsId field and 
+        // the related object is using auto-assigned identity
+        // If the above conditions are satisfied and the related instance has
+        // already been inserted in the RowManger, then returns without further
+        // processing
+        if (sm instanceof StateManagerImpl) {
+	        List<FieldMetaData> mappedByIdFields = ((StateManagerImpl)sm).getMappedByIdFields();
+	        if (rel != null && ((ClassMapping)rel.getMetaData()).getTable().getAutoAssignedColumns().length
> 0
+	        &&  mappedByIdFields!= null && mappedByIdFields.contains(field))
{
+	        	row = rm.getRow(((ClassMapping)rel.getMetaData()).getTable(), Row.ACTION_INSERT,
rel, false); 
+	        	if (row != null) return;
+	        }
+        }
+        if (field.getJoinDirection() == FieldMapping.JOIN_INVERSE)
             updateInverse(sm, rel, store, rm);
         else {
-            Row row = field.getRow(sm, store, rm, Row.ACTION_INSERT);
+            if (row == null) row =  field.getRow(sm, store, rm, Row.ACTION_INSERT);
             if (row != null && !field.isBiMTo1JT()) {
                 field.setForeignKey(row, rel);
                 // this is for bi-directional maps, the key and value of the 

Modified: openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java?rev=1484300&r1=1484299&r2=1484300&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java
(original)
+++ openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java
Sun May 19 15:44:19 2013
@@ -459,4 +459,18 @@ public class PrimaryRow
                 _callbacks.length);
         }
     }
+    
+    public String toString() {
+    	StringBuilder buf = new StringBuilder();
+    	buf.append("PrimaryRow[");
+    	switch (getAction()) {
+	    	case ACTION_UPDATE: buf.append("UPDATE"); break;
+	    	case ACTION_INSERT: buf.append("INSERT"); break;
+	    	case ACTION_DELETE: buf.append("DELETE"); break;
+	    	default: buf.append("UNKNOWN");
+    	}
+    	buf.append(" ").append(getTable().getName()).append("]: ");
+    	buf.append(_pk);
+    	return buf.toString();
+    }
 }

Modified: openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java?rev=1484300&r1=1484299&r2=1484300&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java
(original)
+++ openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java
Sun May 19 15:44:19 2013
@@ -897,6 +897,7 @@ public class RowImpl
                 idx++;
             }
         }
+        setFlushed(true);
     }
 
     /**

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=1484300&r1=1484299&r2=1484300&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
Sun May 19 15:44:19 2013
@@ -3402,4 +3402,8 @@ public class StateManagerImpl
     public void setPc(PersistenceCapable pc) {
         _pc = pc;
     }
+
+    public String toString() {
+    	return "SM[" + _meta.getDescribedType().getSimpleName() + "]:" + getObjectId(); 
+    }
 }

Propchange: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Sun May 19 15:44:19 2013
@@ -0,0 +1 @@
+/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany:1484287



Mime
View raw message