I will not call UserTransaction.begin() when all db operations are SELECT.
I create a EntityManager from emf to do SELECT stuff with no transaction at

When I detected there're some update/delete operations, I'll do this:
1. close the former created EntityManager if there is one (for precedent
2. call UserTransaction.begin()
3. create a new EntityManager
4. do left jobs
5. commint() on success or rollback() on failure.
*. finally (always) close the em (bounded to current thread) and set current
ThreadLocal<EntityManger> to null.

This worked for me in the last three years in several heavy loaded websites.


2010/3/31 Scott Ferguson <f...@caucho.com>

> Why would calling UserTransaction in your code be faster? Essentially,
> all @TransactionAttribute does is call UserTransaction.begin() and
> commit(). (Any extra overhead should be minimal, especially compared to
> the actual transaction.)
> -- Scott
resin-interest mailing list

Reply via email to