diff --git a/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java b/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java
index 092d055..9b24672 100644
--- a/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java
+++ b/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java
@@ -24,6 +24,7 @@
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
@@ -53,7 +54,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
return handleCreateQueryWithString(method, args);
}
- return method.invoke(delegate, args);
+ return invokeMethod(method, args);
}
protected Object handleCreateQueryWithString(Method method, Object[] args) throws Throwable {
@@ -72,7 +73,7 @@ protected Object handleCreateQueryWithString(Method method, Object[] args) throw
}
return query;
} else {
- return method.invoke(delegate, args);
+ return invokeMethod(method, args);
}
}
@@ -82,4 +83,19 @@ private Expressions getExpressions() {
}
return expressions;
}
+
+ /**
+ * Invokes the method on the delegate and unwraps any original Exceptions
+ */
+ private Object invokeMethod(Method method, Object[] args) throws Throwable {
+ try {
+ return method.invoke(delegate, args);
+ }
+ catch(InvocationTargetException e) {
+ if (e.getCause() != null) {
+ throw e.getCause();
+ }
+ throw e;
+ }
+ }
}
diff --git a/testsuite/pom.xml b/testsuite/pom.xml
index 7fae757..228e77d 100644
--- a/testsuite/pom.xml
+++ b/testsuite/pom.xml
@@ -232,6 +232,18 @@
pom
test
+
+
+ org.hibernate
+ hibernate-search
+ test
+
+
+ org.jboss.logging
+ jboss-logging
+
+
+
@@ -274,6 +286,18 @@
pom
test
+
+
+ org.hibernate
+ hibernate-search
+ test
+
+
+ org.jboss.logging
+ jboss-logging
+
+
+
diff --git a/testsuite/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTestBase.java b/testsuite/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTestBase.java
index 3e404ed..f2b2276 100644
--- a/testsuite/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTestBase.java
+++ b/testsuite/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTestBase.java
@@ -20,6 +20,7 @@
import javax.inject.Inject;
import javax.persistence.EntityManager;
+import javax.persistence.EntityNotFoundException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
@@ -66,5 +67,26 @@ public void testManagedPersistenceContext() throws NotSupportedException, System
Assert.assertEquals(1, hotels.size());
transaction.rollback();
}
+
+ @Test(expected = EntityNotFoundException.class)
+ public void testManagedPersistenceContextException() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
+ transaction.begin();
+ Hotel h = new Hotel("test3", "Purkynova", "Brno", "CZ", "63100", "Czech Republic");
+ em.persist(h);
+ em.flush();
+ transaction.commit();
+ transaction.begin();
+ int affected = em.createQuery("delete from Hotel h where h.name = :name").setParameter("name", h.getName()).executeUpdate();
+ Assert.assertEquals(1, affected);
+ transaction.commit();
+
+ try {
+ transaction.begin();
+ em.refresh(h);
+ }
+ finally {
+ transaction.rollback();
+ }
+ }
}