I’m using spring with JPA. And I’ve got two EntityManagers that contain different entities (different modules of one application), and both point to the same datasource.
Can I use both of them in one transaction (using single TransactionManager) ?
Do I have to use JTA for that ? If so what is the best option to use it under tomcat ?
How do I configure it in spring ?
Both standard JPA transactions and Spring’s
JpaTransactionManagerare bound to a singleEntityManager. They cannot talk to multiple managers, and so cann’t coordinate a transaction across them.If you need to do this, you either need to merge your entity manager configs so you have just one
EntityManager, or use JTA transactions (via Spring’s JtaTransactionManager).If you’re using Tomcat (which has no out-of-the-box JTA support), then you’ll need to find a third party JTA implementation.