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

View File

@ -25,6 +25,7 @@ package org.hibernate.envers.tools;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.Session; import org.hibernate.Session;
import java.util.*; import java.util.*;
@ -66,20 +67,21 @@ public class Tools {
return session.getEntityPersister(null, obj).getIdentifier(obj, session.getEntityMode()); 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()) { if (!proxy.getHibernateLazyInitializer().isUninitialized()) {
return proxy.getHibernateLazyInitializer().getImplementation(); return proxy.getHibernateLazyInitializer().getImplementation();
} }
Session tempSession = proxy.getHibernateLazyInitializer().getSession().getFactory().openTemporarySession(); SessionImplementor sessionImplementor = proxy.getHibernateLazyInitializer().getSession();
try { Session tempSession = sessionImplementor==null ? sessionFactoryImplementor.openTemporarySession() : sessionImplementor.getFactory().openTemporarySession();
proxy.getHibernateLazyInitializer().setSession((SessionImplementor) tempSession); try {
proxy.getHibernateLazyInitializer().initialize(); proxy.getHibernateLazyInitializer().setSession((SessionImplementor) tempSession);
return proxy.getHibernateLazyInitializer().getImplementation(); proxy.getHibernateLazyInitializer().initialize();
} finally { return proxy.getHibernateLazyInitializer().getImplementation();
tempSession.close(); } finally {
} tempSession.close();
} }
}
public static boolean objectsEqual(Object obj1, Object obj2) { public static boolean objectsEqual(Object obj1, Object obj2) {
if (obj1 == null) { 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. * @param list List to transform.
* @return A list of pairs: ((0, element_at_index_0), (1, element_at_index_1), ...) * @return A list of pairs: ((0, element_at_index_0), (1, element_at_index_1), ...)
*/ */