This is probably caused by a different exception caught inside the
Spring JpaTransactionManager. Part of the exception handling is to
sometimes call close on the entity manager. This close call should
probably be wrapped in a try/catch block so the original exception can
be re-thrown even if the close call throws a new eception.
Here is what I believe is the offending code:
catch (TransactionException ex) {
if (txObject.isNewEntityManagerHolder()) {
em.close();
}
throw ex;
}
catch (Exception ex) {
if (txObject.isNewEntityManagerHolder()) {
em.close();
}
throw new CannotCreateTransactionException("Could not open
JPA EntityManager for transaction", ex);
}
I have created a Spring JIRA issue for this -
http://jira.springframework.org/browse/SPR-4311
Cheers,
Thomas Risberg
Craig L Russell wrote:
Hi Geir,
The stack trace looks like the springframework is confused.
Do you have any transaction requirements specified on the method that
is executing the query? That's what I assume is causing the call from
the proxy into the transaction framework.
How are you defining the em variable. Is it injected, or do you manage
it yourself?
The strangest thing is where doBegin calls em.close(). I can't explain
this part.
Craig
On Jan 9, 2008, at 7:47 AM, Geir Magnusson Jr. wrote:
<openjpa-1.0.1-r420667:592145 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException: This operation
cannot be performed while a Transaction is active.
at org.apache.openjpa.kernel.BrokerImpl.close(BrokerImpl.java:4014)
at
org.apache.openjpa.kernel.DelegatingBroker.close(DelegatingBroker.java:1282)
at
org.apache.openjpa.persistence.EntityManagerImpl.close(EntityManagerImpl.java:1002)
at
org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:372)
at
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:350)
at
org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:262)
at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:102)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy31.loadAll(Unknown Source)
at com.joost.md.tools.importexport.OMUtil.getDams(OMUtil.java:184)
I don't understand what's happening here. All that loadAll is doing
is :
em.createNamedQuery(includeHidden ? "dam.all" :
"dam.allvisible").getResultList();
and I'm not doing anything explicit w/ txn. This happens only
rarely. Normally things are peachy.
tia
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:[EMAIL PROTECTED]
P.S. A good JDO? O, Gasp!