Author: adamw
Date: 2009-03-20 10:57:08 -0400 (Fri, 20 Mar 2009)
New Revision: 16204
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java
Log:
Fixed looking for session delegate
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java
===================================================================
---
core/trunk/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java 2009-03-20
13:20:14 UTC (rev 16203)
+++
core/trunk/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java 2009-03-20
14:57:08 UTC (rev 16204)
@@ -43,15 +43,18 @@
/**
* 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 @@
}
if (entityManager.getDelegate() instanceof EntityManager) {
+ entityManager = (EntityManager) entityManager.getDelegate();
if (entityManager.getDelegate() instanceof Session) {
return get((Session) entityManager.getDelegate());
}
Show replies by date