=== 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 @@ -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();