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:
parent
c987deb619
commit
99dac200f2
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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,12 +67,13 @@ 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();
|
||||||
|
Session tempSession = sessionImplementor==null ? sessionFactoryImplementor.openTemporarySession() : sessionImplementor.getFactory().openTemporarySession();
|
||||||
try {
|
try {
|
||||||
proxy.getHibernateLazyInitializer().setSession((SessionImplementor) tempSession);
|
proxy.getHibernateLazyInitializer().setSession((SessionImplementor) tempSession);
|
||||||
proxy.getHibernateLazyInitializer().initialize();
|
proxy.getHibernateLazyInitializer().initialize();
|
||||||
|
|
Loading…
Reference in New Issue