开发者

Question about concurrency with jpa 1.0 transactions

开发者 https://www.devze.com 2023-01-30 17:02 出处:网络
Currently we\'re creating a single EntityManager per request in our web app. We\'re wanting to开发者_JAVA技巧 create a transaction at the beginning of the request and close it at the end to get autom

Currently we're creating a single EntityManager per request in our web app. We're wanting to开发者_JAVA技巧 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号