简体   繁体   中英

JPA and transactions in JTA mode (begin and commit)

I have practiced JTA and RESOURCE_LOCAL modes with JPA, there is a huge difference between those two modes.

When I use RESOURCE_LOCAL , I have to manage transactions myself with EntityTransaction , and when I use JTA it's implicitely done by the application server.

So I would like to know when the begin() and commit() methods are executed in JTA mode.

I assume that when the application server receive a HTTP request it executes " begin() ", and before sending an HTTP response to client it executes " commit() "; also, if an error happens before sending the response, it does a " rollback() ". Am I right ?

The JPA specs do not define an exact spot when begin and commit are triggered when workign with JTA transactions.

The transaction control has nothing to do with HTTP requests/responses and is not being triggered by them.

A JTA transaction will be provided for all transactional methods (all EJB methods per default) independent of their purpose.

However there are some guarantees considering JTA transactions and JPA. The transaction is guaranteed to have started when the first call to an EntityManager is made and is guaranteed to either commit or rollback before the method returns.

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