简体   繁体   中英

Question about concurrency with jpa 1.0 transactions

Currently we're creating a single EntityManager per request in our web app. We're wanting to create a transaction at the beginning of the request and close it at the end to get automatic transaction support throughout the entire request.

Has anyone tried this? and will this introduce concurrency issues or is should we just wrap all of our update code in a separate transaction?

Note we're using JPA 1.0

For simple apps, this is enough (one transaction per request). But for more complex scenarios you will need to use transactions on more granular level.

In principle I always wrap my update transactions as needed.

Anyway your approach doesn't prevent you to open a new transaction in the middle of the request if needed. So it is OK by me.

And something about the possible concurrency issues... If you can foresee issues, address them, otherwise I wouldn't worry too much about it. Keep it simple and don't get caught up in premature optimizations

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