diff --git a/envers/src/main/java/org/hibernate/envers/tools/Tools.java b/envers/src/main/java/org/hibernate/envers/tools/Tools.java index e52a777fc5..c1acd6e751 100644 --- a/envers/src/main/java/org/hibernate/envers/tools/Tools.java +++ b/envers/src/main/java/org/hibernate/envers/tools/Tools.java @@ -73,12 +73,22 @@ public class Tools { } SessionImplementor sessionImplementor = proxy.getHibernateLazyInitializer().getSession(); - Session tempSession = sessionImplementor==null ? sessionFactoryImplementor.openTemporarySession() : sessionImplementor.getFactory().openTemporarySession(); + Session tempSession = sessionImplementor==null + ? sessionFactoryImplementor.openTemporarySession() + : sessionImplementor.getFactory().openTemporarySession(); try { - proxy.getHibernateLazyInitializer().setSession((SessionImplementor) tempSession); - proxy.getHibernateLazyInitializer().initialize(); - return proxy.getHibernateLazyInitializer().getImplementation(); - } finally { + Object target = tempSession.get( + proxy.getHibernateLazyInitializer().getEntityName(), + proxy.getHibernateLazyInitializer().getIdentifier() + ); + proxy.getHibernateLazyInitializer().setImplementation( target ); + return target; +// adam, changes in AbstractLazyInitializer render this no longer valid... +// proxy.getHibernateLazyInitializer().setSession((SessionImplementor) tempSession); +// proxy.getHibernateLazyInitializer().initialize(); +// return proxy.getHibernateLazyInitializer().getImplementation(); + } + finally { tempSession.close(); } }