HHH-4449:

- applying patch

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17587 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Adam Warski 2009-09-30 17:16:01 +00:00
parent c987deb619
commit 99dac200f2
2 changed files with 18 additions and 16 deletions

View File

@ -104,7 +104,7 @@ public class AuditEventListener implements PostInsertEventListener, PostUpdateEv
toEntityName = session.bestGuessEntityName(newValue);
id = hibernateProxy.getHibernateLazyInitializer().getIdentifier();
// We've got to initialize the object from the proxy to later read its state.
newValue = Tools.getTargetFromProxy(hibernateProxy);
newValue = Tools.getTargetFromProxy(session.getFactory(), hibernateProxy);
} else {
toEntityName = session.guessEntityName(newValue);
@ -124,7 +124,7 @@ public class AuditEventListener implements PostInsertEventListener, PostUpdateEv
toEntityName = session.bestGuessEntityName(oldValue);
id = hibernateProxy.getHibernateLazyInitializer().getIdentifier();
// We've got to initialize the object as we'll read it's state anyway.
oldValue = Tools.getTargetFromProxy(hibernateProxy);
oldValue = Tools.getTargetFromProxy(session.getFactory(), hibernateProxy);
} else {
toEntityName = session.guessEntityName(oldValue);

View File

@ -25,6 +25,7 @@ package org.hibernate.envers.tools;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.Session;
import java.util.*;
@ -66,12 +67,13 @@ public class Tools {
return session.getEntityPersister(null, obj).getIdentifier(obj, session.getEntityMode());
}
public static Object getTargetFromProxy(HibernateProxy proxy) {
public static Object getTargetFromProxy(SessionFactoryImplementor sessionFactoryImplementor, HibernateProxy proxy) {
if (!proxy.getHibernateLazyInitializer().isUninitialized()) {
return proxy.getHibernateLazyInitializer().getImplementation();
}
Session tempSession = proxy.getHibernateLazyInitializer().getSession().getFactory().openTemporarySession();
SessionImplementor sessionImplementor = proxy.getHibernateLazyInitializer().getSession();
Session tempSession = sessionImplementor==null ? sessionFactoryImplementor.openTemporarySession() : sessionImplementor.getFactory().openTemporarySession();
try {
proxy.getHibernateLazyInitializer().setSession((SessionImplementor) tempSession);
proxy.getHibernateLazyInitializer().initialize();