@@ -0,0 +1,1100 @@
+package net.etalia.crepuscolo.utils;%0A%0Aimport java.lang.reflect.Method;%0A%0Apublic class HibernateUnwrapper %7B%0A%0A%09private static Class%3C?%3E hproxyClazz = null;%0A%09private static Method unwrapGetInitializer = null;%0A%09private static Method unwrapGetInstance = null;%0A%0A%09static %7B%0A%09%09try %7B%0A%09%09%09hproxyClazz = Class.forName(%22org.hibernate.proxy.HibernateProxy%22);%0A%09%09%09unwrapGetInitializer = hproxyClazz.getDeclaredMethod(%22getHibernateLazyInitializer%22);%0A%09%09%09Class%3C?%3E lazyInitializer = Class.forName(%22org.hibernate.proxy.LazyInitializer%22);%0A%09%09%09unwrapGetInstance = lazyInitializer.getDeclaredMethod(%22getImplementation%22);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09hproxyClazz = null;%0A%09%09%09unwrapGetInitializer = null;%0A%09%09%09unwrapGetInstance = null;%0A%09%09%7D%0A%09%7D%0A%0A%09@SuppressWarnings(%22unchecked%22)%0A%09public static %3CT%3E T unwrap(T obj) %7B%0A%09%09if (obj == null) return null;%0A%09%09if (hproxyClazz == null) return obj;%0A%09%09if (hproxyClazz.isInstance(obj)) %7B%0A%09%09%09try %7B%0A%09%09%09%09Object initializer = unwrapGetInitializer.invoke(obj);%0A%09%09%09%09return (T)unwrapGetInstance.invoke(initializer);%0A%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09throw new RuntimeException(e);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return obj;%0A%09%7D%0A%0A%7D%0A

Add more classes