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,20 +67,21 @@ public class Tools {
return session.getEntityPersister(null, obj).getIdentifier(obj, session.getEntityMode());
}
public static Object getTargetFromProxy(HibernateProxy proxy) {
if (!proxy.getHibernateLazyInitializer().isUninitialized()) {
return proxy.getHibernateLazyInitializer().getImplementation();
}
public static Object getTargetFromProxy(SessionFactoryImplementor sessionFactoryImplementor, HibernateProxy proxy) {
if (!proxy.getHibernateLazyInitializer().isUninitialized()) {
return proxy.getHibernateLazyInitializer().getImplementation();
}
Session tempSession = proxy.getHibernateLazyInitializer().getSession().getFactory().openTemporarySession();
try {
proxy.getHibernateLazyInitializer().setSession((SessionImplementor) tempSession);
proxy.getHibernateLazyInitializer().initialize();
return proxy.getHibernateLazyInitializer().getImplementation();
} finally {
tempSession.close();
}
}
SessionImplementor sessionImplementor = proxy.getHibernateLazyInitializer().getSession();
Session tempSession = sessionImplementor==null ? sessionFactoryImplementor.openTemporarySession() : sessionImplementor.getFactory().openTemporarySession();
try {
proxy.getHibernateLazyInitializer().setSession((SessionImplementor) tempSession);
proxy.getHibernateLazyInitializer().initialize();
return proxy.getHibernateLazyInitializer().getImplementation();
} finally {
tempSession.close();
}
}
public static boolean objectsEqual(Object obj1, Object obj2) {
if (obj1 == null) {
@ -113,7 +115,7 @@ public class Tools {
}
/**
* Transforms a list of arbitrary elements to a list of index-element pairs.
* Transforms a list of arbitrary elements to a list of index-element pairs.
* @param list List to transform.
* @return A list of pairs: ((0, element_at_index_0), (1, element_at_index_1), ...)
*/