문제

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 JpaTransactionManager are bound to a single EntityManager. 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top