openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dian...@apache.org
Subject svn commit: r1293315 - /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
Date Fri, 24 Feb 2012 16:09:31 GMT
Author: dianner
Date: Fri Feb 24 16:09:31 2012
New Revision: 1293315

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

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java?rev=1293315&r1=1293314&r2=1293315&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
Fri Feb 24 16:09:31 2012
@@ -92,8 +92,30 @@ abstract class AttachStrategy
         else // application identity: use existing fields
             newInstance = pc.pcNewInstance(null, appId, false);
 
-        return (StateManagerImpl) manager.getBroker().persist
+        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() && fmd.getDeclaredTypeCode() == JavaTypes.PC)
{
+                    attachField(manager, fromPC, sm, fmd, true);
+                }
+            }
+        
+            fromPC.pcReplaceStateManager(null);
+        }
     }
 
     /**



Mime
View raw message