Question about concurrency with jpa 1.0 transactions

214 views Asked by At

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

1

There are 1 answers

0
Bojan Milenkoski On BEST ANSWER

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