简体   繁体   中英

JPA multiple persistence persistence units and JTA transaction

I have an OSGi project with multiple bundles containing JPA model classes as well as the corresponding persistence.xml. All PUs use JTA as its transaction-type and are connected to the same database (they use the same DataSource).

When manipulating entities I use different EntityManagers and everything is working fine as long as I use an XADataSource. My thinking now is that since they use the same database and the same transaction-manager XA transactions shouldn't be necessary. Though if I switch to a plain DataSource I start seeing inconsistencies in case of rollbacks.

I looked through the specs but couldn't find anything related to this. Does anyone have a pointer whether XA transactions are required as part of such a setup?

Thanks, Philipp

If you use different persistence units then each will have its own connection to the database. So even if you use the same DataSource they will not use the same transaction. So I think this is why you might have problems during rollback.

In jta the transaction can span the different connections and so it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM