openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ming Fai Ma" <>
Subject Problem with Spring managed transaction in JBoss
Date Sun, 06 Jan 2008 08:05:33 GMT

I got a strange problem that when using Spring managed transaction with
injected persistence context ( i.e. @PersistenceContext private
EntityManager em; ) when deployed to JBoss (not using the default unified
classloader). By debugging at the OpenJPA code and also from the stacktrace,
a newly created Query object is not opened. So for the first time I call
setParameter, exception is thrown from the assertOpen method of the

<><openjpa-1.0.1-r420667:592145 fatal user error>
org.apache.openjpa.persistence.InvalidStateException: The context has been
closed.  The stack trace at which the context was closed is held in the
embedded exception.
FailedObject: java.lang.IllegalStateException
    at org.apache.openjpa.kernel.BrokerImpl.assertOpen(
    at org.apache.openjpa.kernel.QueryImpl.assertOpen(
    at org.apache.openjpa.kernel.DelegatingQuery.assertOpen(
    at org.apache.openjpa.persistence.QueryImpl.setParameter(
    at org.apache.openjpa.persistence.QueryImpl.setParameter(

At the following Spring JPA log, the first two lines show my previous
transaction is successful and the EM was closed, and then (after I click
another page that) I trigger a query that create a new EM and then an
exception is thrown.
2008-01-06 15:12:50,454 DEBUG [
org.springframework.orm.jpa.JpaTransactionManager] Triggering
afterCompletion synchronization
2008-01-06 15:12:50,454 DEBUG [
org.springframework.orm.jpa.JpaTransactionManager] Closing JPA EntityManager
[org.apache.openjpa.persistence.EntityManagerImpl@1160709] after transaction
2008-01-06 15:12:51,860 DEBUG [
Creating new EntityManager for shared EntityManager invocation

The case is complex as,

   1. my code has no exception if I use programmatic transaction instead
   of Spring managed transaction. It's just not as elegant as the Spring
   managed transaction code.
   2. It is normal for Spring to start a new Entity Manager according to
   the Spring doc and also a thread about multi-thread transaction *[1]
   3. The Spring managed transaction code does work outside JBoss. I have
   a unit test that use mock objects to simulate the whole
   WebApplicationContext and there is no exception. There is exception only
   when the application is run inside JBoss under a non-unified classloader.

I guess it is not a problem with OpenJPA, but an issue with Spring in JBoss.
However, as the exception in the OpenJPA code, I'd like to get some ideas
from this mail list in order to figure out how should I ask in the
Spring/JBoss forum. For example, in what scenario a new Entity Manager may
create Query that is not opened by default?  Any idea?

Thank you in advance.


[1] -

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message