In my case of application managed transaction, I've to choose between:
EntityManager
and calling clear()
before each new transaction. Share the EntityManager
using a ThreadLocal
.EntityManager
for each transaction.I don't have much experience on JPA. My question is which one is better in terms of performance?
I would recommend creating a new EntityManager per transaction. This is the way JPA was designed. The EntityManager should not be an expensive object to create. (the EntityManagerFactory is very expensive though, so ensure you only have one of those).