diff --git a/cache-jbosscache2/pom.xml b/cache-jbosscache2/pom.xml
index a43b370ce1..9dd2ec3f4c 100644
--- a/cache-jbosscache2/pom.xml
+++ b/cache-jbosscache2/pom.xml
@@ -58,7 +58,8 @@
org.hibernate.java-persistence
jpa-api
- 2.0.Beta1
+ 2.0.Beta2
+ test
diff --git a/envers/pom.xml b/envers/pom.xml
index d42249b757..b2537a1057 100644
--- a/envers/pom.xml
+++ b/envers/pom.xml
@@ -72,7 +72,6 @@
org.hibernate.java-persistence
jpa-api
- 2.0.Beta1
org.hibernate
@@ -151,9 +150,9 @@
3.2.0.ga
- javax.persistence
- persistence-api
- 1.0
+ org.hibernate.java-persistence
+ jpa-api
+ 2.0.Beta2
ant
diff --git a/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java b/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java
index 1fbf096025..21ba071873 100644
--- a/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java
+++ b/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java
@@ -24,14 +24,14 @@
package org.hibernate.envers;
import javax.persistence.EntityManager;
-import javax.persistence.PersistenceException;
-import org.hibernate.Session;
-import org.hibernate.engine.SessionImplementor;
import org.hibernate.envers.event.AuditEventListener;
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.reader.AuditReaderImpl;
import static org.hibernate.envers.tools.ArraysTools.arrayIncludesInstanceOf;
+
+import org.hibernate.Session;
+import org.hibernate.engine.SessionImplementor;
import org.hibernate.event.EventListeners;
import org.hibernate.event.PostInsertEventListener;
@@ -81,11 +81,17 @@ public class AuditReaderFactory {
* listeners aren't installed.
*/
public static AuditReader get(EntityManager entityManager) throws AuditException {
- try {
- return get( entityManager.unwrap(Session.class) );
- }
- catch ( PersistenceException e ) {
- throw new AuditException("Hibernate EntityManager not present!");
- }
+ if (entityManager.getDelegate() instanceof Session) {
+ return get((Session) entityManager.getDelegate());
+ }
+
+ if (entityManager.getDelegate() instanceof EntityManager) {
+ entityManager = (EntityManager) entityManager.getDelegate();
+ if (entityManager.getDelegate() instanceof Session) {
+ return get((Session) entityManager.getDelegate());
+ }
+ }
+
+ throw new AuditException("Hibernate EntityManager not present!");
}
}
diff --git a/envers/src/main/java/org/jboss/envers/VersionsReaderFactory.java b/envers/src/main/java/org/jboss/envers/VersionsReaderFactory.java
index 9d9ec82cfb..25de4b2436 100644
--- a/envers/src/main/java/org/jboss/envers/VersionsReaderFactory.java
+++ b/envers/src/main/java/org/jboss/envers/VersionsReaderFactory.java
@@ -25,7 +25,6 @@
package org.jboss.envers;
import javax.persistence.EntityManager;
-import javax.persistence.PersistenceException;
import org.hibernate.envers.event.AuditEventListener;
import org.hibernate.envers.reader.AuditReaderImpl;
@@ -82,11 +81,16 @@ public class VersionsReaderFactory {
* listeners aren't installed.
*/
public static VersionsReader get(EntityManager entityManager) throws VersionsException {
- try {
- return get( entityManager.unwrap(Session.class) );
- }
- catch ( PersistenceException e ) {
- throw new VersionsException("Hibernate EntityManager not present!");
- }
+ if (entityManager.getDelegate() instanceof Session) {
+ return get((Session) entityManager.getDelegate());
+ }
+
+ if (entityManager.getDelegate() instanceof EntityManager) {
+ if (entityManager.getDelegate() instanceof Session) {
+ return get((Session) entityManager.getDelegate());
+ }
+ }
+
+ throw new VersionsException("Hibernate EntityManager not present!");
}
}
\ No newline at end of file
diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/flush/AbstractFlushTest.java b/envers/src/test/java/org/hibernate/envers/test/integration/flush/AbstractFlushTest.java
index 96df2e48b0..647f483897 100644
--- a/envers/src/test/java/org/hibernate/envers/test/integration/flush/AbstractFlushTest.java
+++ b/envers/src/test/java/org/hibernate/envers/test/integration/flush/AbstractFlushTest.java
@@ -25,7 +25,6 @@ package org.hibernate.envers.test.integration.flush;
import java.io.IOException;
import javax.persistence.EntityManager;
-import javax.persistence.PersistenceException;
import org.hibernate.envers.test.AbstractEntityTest;
import org.hibernate.envers.test.entities.StrTestEntity;
@@ -46,12 +45,18 @@ public abstract class AbstractFlushTest extends AbstractEntityTest {
}
private static Session getSession(EntityManager em) {
- try {
- return em.unwrap( Session.class );
- }
- catch ( PersistenceException e ) {
- throw new RuntimeException("Invalid entity manager", e);
- }
+ Object delegate = em.getDelegate();
+ if (delegate instanceof Session) {
+ return (Session) delegate;
+ } else if (delegate instanceof EntityManager) {
+ Object delegate2 = ((EntityManager) delegate).getDelegate();
+
+ if (delegate2 instanceof Session) {
+ return (Session) delegate2;
+ }
+ }
+
+ throw new RuntimeException("Invalid entity manager");
}
@BeforeClass(dependsOnMethods = "init")
diff --git a/envers/src/test/java/org/hibernate/envers/test/various/HsqlTest.java b/envers/src/test/java/org/hibernate/envers/test/various/HsqlTest.java
index c50b41a722..dcc62dc424 100644
--- a/envers/src/test/java/org/hibernate/envers/test/various/HsqlTest.java
+++ b/envers/src/test/java/org/hibernate/envers/test/various/HsqlTest.java
@@ -100,7 +100,7 @@ public class HsqlTest {
entityManager.getTransaction().begin();
- Session sesion = entityManager.unwrap(Session.class);
+ Session sesion = (Session) entityManager.getDelegate();
System.out.println(sesion.createQuery(
"select e from org.hibernate.envers.demo.Person_versions e " +
"where " +