JpaLocalTxnInterceptor closes entitymanager before transaction is commited

40 views
Skip to first unread message

Adrian

unread,
Oct 20, 2007, 4:40:14 AM10/20/07
to warp-core
openjpa throws an exception, because JpaLocalTxnInterceptor closes the
entitymanager before it commits the transaction

is the implementation wrong or my usage of @transactional?

> 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
com.wideplay.warp.jpa.EntityManagerFactoryHolder.closeCurrentEntityManager(EntityManagerFactoryHolder.java:
58)
at
com.wideplay.warp.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:
61)

Dhanji R. Prasanna

unread,
Oct 20, 2007, 5:08:20 AM10/20/07
to warp...@googlegroups.com
Hi Adrian

JpaLocalTxnInterceptor does commit or rollback the active txn before
trying to close the EM, so I'm not sure what could be wrong from the
information given. There is a potential corner case where txn commit()
throws and exception itself, but there are tests that assure against
this case for Hibernate--not tested with OpenJPA =(

Can you post the offending code (i.e. the method marked
@Transactional) and your module configuration?

Also make sure you are using the latest warp-persist binary, if you
downloaded it from the site.

Dhanji.

Adrian

unread,
Oct 20, 2007, 6:22:11 AM10/20/07
to warp-core
thanks for the fast anwser.
see in current revision 54 of JpaLocalTxnInterceptor::invoke()

first, it tries to join to a active transaction --> ok
the first try/catch/finally starts the transaction txn.begin,
but in this finally block it closes the entitymanager:
} finally {
//close the em if necessary
if (isUnitOfWorkTransaction()) {

EntityManagerFactoryHolder.closeCurrentEntityManager();
}
}

later it commits the transaction

my patch (but im not expert enough ..)
Index: src/com/wideplay/warp/jpa/JpaLocalTxnInterceptor.java
===================================================================
--- src/com/wideplay/warp/jpa/JpaLocalTxnInterceptor.java (revision
60)
+++ src/com/wideplay/warp/jpa/JpaLocalTxnInterceptor.java (working
copy)
@@ -57,7 +57,7 @@
throw e;
} finally {
//close the em if necessary
- if (isUnitOfWorkTransaction()) {
+ if (isUnitOfWorkTransaction() && !txn.isActive()) {

EntityManagerFactoryHolder.closeCurrentEntityManager();
}
}

On Oct 20, 11:08 am, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:
> Hi Adrian
>
> JpaLocalTxnInterceptor does commit or rollback the active txn before
> trying to close the EM, so I'm not sure what could be wrong from the
> information given. There is a potential corner case where txn commit()
> throws and exception itself, but there are tests that assure against
> this case for Hibernate--not tested with OpenJPA =(
>
> Can you post the offending code (i.e. the method marked
> @Transactional) and your module configuration?
>
> Also make sure you are using the latest warp-persist binary, if you
> downloaded it from the site.
>
> Dhanji.
>

Dhanji R. Prasanna

unread,
Oct 21, 2007, 9:44:17 PM10/21/07
to warp...@googlegroups.com
Hmm, good point. Give me a few hours to look into this. I'll try to
triangulate this error with Hibernate (which seems to work
optimistically) so it's test covered.

Thanks for reporting this!!!

Dhanji.

On 10/20/07, Adrian <space...@gmail.com> wrote:
>

Dhanji R. Prasanna

unread,
Oct 25, 2007, 7:36:05 AM10/25/07
to warp...@googlegroups.com
FYI This change has been committed (and the distro updated).
Unfortunately I didnt have enough time to write a special test to
triangulate this issue (nor think of a smart solution to it).

Plz report any errors you find with this or if you would like to
contrib a test for this issue that would be great.

Thanks again for reporting it. This is how we make warp better. =)

Dhanji.

Reply all
Reply to author
Forward
0 new messages