From 7e6bc6f5e62793d5221b1d84b5aead4e26f3e465 Mon Sep 17 00:00:00 2001 From: Alejandro Revilla Date: Wed, 16 Dec 2015 22:55:54 -0300 Subject: [PATCH] added handy unwrap proxy helper --- .../dbsupport/src/main/java/org/jpos/ee/DB.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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() {