diff --git a/modules/dbsupport/src/main/java/org/jpos/ee/DB.java b/modules/dbsupport/src/main/java/org/jpos/ee/DB.java index 522587165d..397902005e 100644 --- a/modules/dbsupport/src/main/java/org/jpos/ee/DB.java +++ b/modules/dbsupport/src/main/java/org/jpos/ee/DB.java @@ -22,10 +22,7 @@ import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.Transaction; +import org.hibernate.*; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.spi.MetadataImplementor; @@ -33,6 +30,7 @@ import org.hibernate.engine.spi.CollectionKey; import org.hibernate.engine.spi.EntityKey; import org.hibernate.internal.util.ReflectHelper; +import org.hibernate.proxy.HibernateProxy; import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.stat.SessionStatistics; import org.hibernate.tool.hbm2ddl.SchemaExport; @@ -375,6 +373,14 @@ public static Object execWithTransaction(DBAction action) } } + @SuppressWarnings("unchecked") + public static T unwrap (T proxy) { + Hibernate.getClass(proxy); + Hibernate.initialize(proxy); + return (proxy instanceof HibernateProxy) ? + (T) ((HibernateProxy) proxy).getHibernateLazyInitializer().getImplementation() : proxy; + } + @SuppressWarnings({"unchecked"}) public void printStats() {