← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21656: fix to property handle unwrapping of Hibernate PersistentSet and HibernateProxy

 

------------------------------------------------------------
revno: 21656
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-01-08 11:00:42 +0700
message:
  fix to property handle unwrapping of Hibernate PersistentSet and HibernateProxy
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/HibernateUtils.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/HibernateUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/HibernateUtils.java	2016-01-06 07:05:53 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/HibernateUtils.java	2016-01-08 04:00:42 +0000
@@ -32,6 +32,11 @@
 import org.hibernate.collection.internal.PersistentSet;
 import org.hibernate.collection.spi.PersistentCollection;
 import org.hibernate.proxy.HibernateProxy;
+import org.hibernate.proxy.pojo.javassist.SerializableProxy;
+
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Map;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -64,6 +69,16 @@
             return (T) ((HibernateProxy) proxy).getHibernateLazyInitializer().getImplementation();
         }
 
+        if ( HibernateProxy.class.isInstance( proxy ) )
+        {
+            Object result = ((HibernateProxy) proxy).writeReplace();
+
+            if ( !SerializableProxy.class.isInstance( result ) )
+            {
+                return (T) result;
+            }
+        }
+
         if ( PersistentCollection.class.isInstance( proxy ) )
         {
             PersistentCollection persistentCollection = (PersistentCollection) proxy;
@@ -72,6 +87,11 @@
             {
                 return (T) persistentCollection.getStoredSnapshot();
             }
+            else if ( PersistentSet.class.isInstance( persistentCollection ) )
+            {
+                Map<?, ?> map = (Map<?, ?>) persistentCollection.getStoredSnapshot();
+                return (T) new LinkedHashSet<>( map.keySet() );
+            }
 
             // for now just return same as for non-sets, but PersistentSets might require a bit of extra work.
             return (T) persistentCollection.getStoredSnapshot();