Fixed looking for session delegate
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@16204 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
fd8f6fbbaa
commit
996f87451b
|
@ -43,15 +43,18 @@ public class AuditReaderFactory {
|
|||
|
||||
/**
|
||||
* Create an audit reader associated with an open session.
|
||||
* <b>WARNING:</b> Using Envers with Hibernate (not with Hibernate Entity Manager/JPA) is experimental,
|
||||
* if possible, use {@link AuditReaderFactory#get(javax.persistence.EntityManager)}.
|
||||
* @param session An open session.
|
||||
* @return An audit reader associated with the given sesison. It shouldn't be used
|
||||
* after the session is closed.
|
||||
* @throws AuditException When the given required listeners aren't installed.
|
||||
*/
|
||||
public static AuditReader get(Session session) throws AuditException {
|
||||
SessionImplementor sessionImpl = (SessionImplementor) session;
|
||||
SessionImplementor sessionImpl;
|
||||
if (!(session instanceof SessionImplementor)) {
|
||||
sessionImpl = (SessionImplementor) session.getSessionFactory().getCurrentSession();
|
||||
} else {
|
||||
sessionImpl = (SessionImplementor) session;
|
||||
}
|
||||
|
||||
EventListeners listeners = sessionImpl.getListeners();
|
||||
|
||||
|
@ -83,6 +86,7 @@ public class AuditReaderFactory {
|
|||
}
|
||||
|
||||
if (entityManager.getDelegate() instanceof EntityManager) {
|
||||
entityManager = (EntityManager) entityManager.getDelegate();
|
||||
if (entityManager.getDelegate() instanceof Session) {
|
||||
return get((Session) entityManager.getDelegate());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue