openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1050169 - /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Proxies.java
Date Thu, 16 Dec 2010 21:29:51 GMT
Author: curtisr7
Date: Thu Dec 16 21:29:51 2010
New Revision: 1050169

URL: http://svn.apache.org/viewvc?rev=1050169&view=rev
Log:
OPENJPA-1900: Fix ClassCastException when serializing a proxy for an Entity that exists in
an active persistence context. Patch contributed by Mark Struberg.

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

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Proxies.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Proxies.java?rev=1050169&r1=1050168&r2=1050169&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Proxies.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Proxies.java Thu Dec
16 21:29:51 2010
@@ -127,8 +127,15 @@ public class Proxies {
             ClassMetaData meta = null;          // if null, no proxies?
             boolean useDSFForUnproxy = false;   // default to false for old 1.0 behavior
 
-            // DetachedStateMnager has no context or metadata, so we can't get configuration
settings
-            if (!proxy.getOwner().isDetached()) {
+            // Don't rely on sm.isDetached() method because if we are serializing an attached
Entity
+            // the sm will still be a StateManagerImpl, but isDetached() will return true.
+
+            // Using a DetachedStateManager, so use the new flag since there is no context
or
+            // metadata
+            if (sm instanceof DetachedStateManager) {
+                useDSFForUnproxy = ((DetachedStateManager) sm).getUseDSFForUnproxy();
+            } else{
+                // DetachedStateManager has no context or metadata, so we can't get configuration
settings
                 Compatibility compat = null;
                 meta = sm.getMetaData();
                 if (meta != null) {
@@ -142,9 +149,6 @@ public class Proxies {
                     // new 2.0 behavior of using DetachedStateField to determine unproxy
during serialization
                     useDSFForUnproxy = !compat.getIgnoreDetachedStateFieldForProxySerialization();
                 }
-            } else {
-                // Using a DetachedStateManager, so use the new flag since there is no context
or metadata
-                useDSFForUnproxy = ((DetachedStateManager)sm).getUseDSFForUnproxy();
             }
             
             if (useDSFForUnproxy) {



Mime
View raw message