openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1504611 - in /openjpa/branches/2.0.x: ./ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persist...
Date Thu, 18 Jul 2013 19:19:25 GMT
Author: hthomann
Date: Thu Jul 18 19:19:24 2013
New Revision: 1504611

URL: http://svn.apache.org/r1504611
Log:
OPENJPA-1983: Don't cascade to an unloaded field when merge is called on a managed Entity
- back ported Rick Curtis' trunk changes to 2.0.x.

Added:
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/TestLazyFields.java
      - copied unchanged from r1095401, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/TestLazyFields.java
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Inner.java
      - copied, changed from r1095401, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Inner.java
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Outer.java
      - copied, changed from r1095401, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Outer.java
Modified:
    openjpa/branches/2.0.x/   (props changed)
    openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java

Propchange: openjpa/branches/2.0.x/
------------------------------------------------------------------------------
  Merged /openjpa/trunk:r1095401,1095805

Modified: openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java?rev=1504611&r1=1504610&r2=1504611&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java
(original)
+++ openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java
Thu Jul 18 19:19:24 2013
@@ -19,6 +19,7 @@
 package org.apache.openjpa.kernel;
 
 import java.util.ArrayList;
+import java.util.BitSet;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
@@ -37,11 +38,11 @@ import org.apache.openjpa.meta.FieldMeta
 import org.apache.openjpa.meta.ValueMetaData;
 import org.apache.openjpa.util.CallbackException;
 import org.apache.openjpa.util.Exceptions;
+import org.apache.openjpa.util.ImplHelper;
 import org.apache.openjpa.util.OpenJPAException;
 import org.apache.openjpa.util.OptimisticException;
 import org.apache.openjpa.util.ProxyManager;
 import org.apache.openjpa.util.UserException;
-import org.apache.openjpa.util.ImplHelper;
 
 /**
  * Handles attaching instances.
@@ -59,7 +60,7 @@ public class AttachManager {
     private final boolean _copyNew;
     private final boolean _failFast;
     private final IdentityMap _attached = new IdentityMap();
-    private final Collection _visitedNodes = new ArrayList();
+    private final Collection<StateManagerImpl> _visitedNodes = new ArrayList();
 
     // reusable strategies
     private AttachStrategy _version = null;
@@ -253,17 +254,18 @@ public class AttachManager {
     }
 
     private Object handleCascade(Object toAttach, OpenJPAStateManager owner) {
-        FieldMetaData[] fields = _broker.getStateManager(toAttach).getMetaData()
-            .getDefinedFields();
-        for (int i = 0; i < fields.length; i++) {
-            FieldMetaData fd = (FieldMetaData) fields[i];
-            if (fd.getElement().getCascadeAttach() == fd.CASCADE_IMMEDIATE) {
-                FieldMetaData[] inverseFieldMappings = fd.getInverseMetaDatas();
+        StateManagerImpl sm = _broker.getStateManagerImpl(toAttach, true);
+        BitSet loaded = sm.getLoaded();
+        FieldMetaData[] fmds = sm.getMetaData().getDefinedFields();
+        for (FieldMetaData fmd : fmds) {
+            if (fmd.getElement().getCascadeAttach() == ValueMetaData.CASCADE_IMMEDIATE) {
+                FieldMetaData[] inverseFieldMappings = fmd.getInverseMetaDatas();
                 if (inverseFieldMappings.length != 0) {
-                    OpenJPAStateManager sm = _broker.getStateManager(toAttach);
                     _visitedNodes.add(sm);
-                    getStrategy(toAttach).attachField(this, toAttach,
-                        _broker.getStateManagerImpl(toAttach, true), fd, true);
+                    // Only try to attach this field is it is loaded
+                    if (loaded.get(fmd.getIndex())) {
+                        getStrategy(toAttach).attachField(this, toAttach, sm, fmd, true);
+                    }
                 }
             }
         }

Copied: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Inner.java
(from r1095401, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Inner.java)
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Inner.java?p2=openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Inner.java&p1=openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Inner.java&r1=1095401&r2=1504611&rev=1504611&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Inner.java
(original)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Inner.java
Thu Jul 18 19:19:24 2013
@@ -35,7 +35,7 @@ import javax.persistence.Table;
 public class Inner {
 
     @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @GeneratedValue(strategy = GenerationType.AUTO)
     private Long id = null;
 
     private String name = null;

Copied: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Outer.java
(from r1095401, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Outer.java)
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Outer.java?p2=openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Outer.java&p1=openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Outer.java&r1=1095401&r2=1504611&rev=1504611&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Outer.java
(original)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/model/Outer.java
Thu Jul 18 19:19:24 2013
@@ -34,7 +34,7 @@ import javax.persistence.Table;
 public class Outer {
 
     @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @GeneratedValue(strategy = GenerationType.AUTO)
     private Long id = null;
 
     private String name = null;



Mime
View raw message