Awesome, we just migrated our application to onami-persist. I had a look at the source code, it looks much better.
Thanks guys. Le jeudi 22 janvier 2015 08:03:35 UTC+11, scl a écrit : > > 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, [email protected] <javascript:> 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 [email protected] <javascript:>. > To post to this group, send email to [email protected] > <javascript:>. > 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 [email protected]. To post to this group, send email to [email protected]. 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/5e0258e2-39ef-472f-bb97-b346e78d839b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
