openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dian...@apache.org
Subject svn commit: r1293310 - /openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
Date Fri, 24 Feb 2012 16:00:16 GMT
Author: dianner
Date: Fri Feb 24 16:00:16 2012
New Revision: 1293310

URL: http://svn.apache.org/viewvc?rev=1293310&view=rev
Log:
OPENJPA-2142 Handle merge of new object with Entity Id field

Modified:
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java?rev=1293310&r1=1293309&r2=1293310&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
Fri Feb 24 16:00:16 2012
@@ -92,9 +92,30 @@ abstract class AttachStrategy
         else // application identity: use existing fields
             newInstance = pc.pcNewInstance(null, appId, false);
 
-        return (StateManagerImpl) manager.getBroker().persist
-            (newInstance, appId, explicit, manager.getBehavior(), !manager.getCopyNew());
+        StateManagerImpl sm = (StateManagerImpl) manager.getBroker().persist
+                (newInstance, appId, explicit, manager.getBehavior(), !manager.getCopyNew());
+        
+        attachPCKeyFields(pc, sm, meta, manager);
+        
+        return sm;
     }
+    
+    private void attachPCKeyFields(PersistenceCapable fromPC, 
+        StateManagerImpl sm, ClassMetaData meta, AttachManager manager) {
+                
+        if (fromPC.pcGetStateManager() == null) {
+            fromPC.pcReplaceStateManager(sm);
+        
+            FieldMetaData[] fmds = meta.getDefinedFields();
+            for (FieldMetaData fmd : fmds) {
+                if (fmd.isPrimaryKey()) {
+                    attachField(manager, fromPC, sm, fmd, true);
+                }
+            }
+        
+            fromPC.pcReplaceStateManager(null);
+        }
+    }    
 
     /**
      * Attach the given field into the given instance.



Mime
View raw message