1

I find myself needing a post commit hook on transactions. I am using an event store and need to guarantee that events are not published until the transaction has been committed, because an event handler might require data from the previous transaction.

I am using Guice with the JPA module to wire everything up. I think I could quite easily add a hook by changing JpaLocalTxnInterceptor from the guice-persist module, I could stop using @Transactional and do it manually but would prefer to hide this boilerplate, is there a better solution?

Alex Edwards
  • 1,533
  • 2
  • 21
  • 47

1 Answers1

0

My proposal is to add a custom interceptor and a custom annotation. You can copy the existing JpaLocalTxnInterceptor to start with.

Other solution is to use JTA and include both the DB and the EventStore into the transaction. But then again distributed transactions are a problem for their own.

By the way. Guice persist does not suoppert JTA. Onami Persist would be an alternative.

sclassen
  • 108
  • 3