Regarding persist-extension see: https://groups.google.com/d/topic/google-guice/Dp9nWdmDbUs/discussion
There are several know bugs.

An alternative implementation exists (currently maintained by me):
http://onami.apache.org/persist/

Cheers


On 01/21/2015 04:49 AM, edouard.kai...@gmail.com wrote:
Hi all,

I'll use Hibernate as an example for the underlying JPA implementation.
In JpaLocalTxnInterceptor.java, line 66, guice-persist starts a transaction with txn.begin().

When Guice asks Hibernate to start a transaction, this is what Hibernates does:
- Fetch a connection
- Tries to disable auto-commit on the connection if autocommit was set to true.

The problem is, sometimes this operation fails (loss of connectivity, whatever...) and an Hibernate exception is thrown (the most curious one can have a look at Hibernate source-code, JdbcTransaction.java, line 72). But guice-persist doesn't catch this potential RuntimeException when it begins a transaction.

And because it doesn't catch it, it doesn't call rollback on the transaction. You might think, why would I call rollback on a transaction which didn't even start ? (keep in mind txn.begin() just failed).

Because the connection fetched by Hibernate is only released in case of commit or rollback. By not calling rollback, the current thread gets stuck in a stale state, and the next time this thread is used for JPA transaction, Hibernate will throw an exception: "Already have an associated managed connection". Because, correct me if I'm wrong, but if txn.begin() raises an exception, unitOfWork.end() is never called, the EntityManager is never closed and removed from ThreadLocal in JpaPersistService.

I had a quick look at the JPA interceptor source code, for Spring Data, they do catch any potential exception, even when they begin a transaction, and call rollback in case of problem.

Any thoughts on this ?

Thanks for your help guys
--
You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+unsubscr...@googlegroups.com <mailto:google-guice+unsubscr...@googlegroups.com>. To post to this group, send email to google-guice@googlegroups.com <mailto:google-guice@googlegroups.com>.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/b74e3ebd-c366-46e6-82ed-f974306cf4fa%40googlegroups.com <https://groups.google.com/d/msgid/google-guice/b74e3ebd-c366-46e6-82ed-f974306cf4fa%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/54C0141F.5050502%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.

Reply via email to