O'Reilly logo

Java EE 7 Developer Handbook by Peter A. Pilgrim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Transactions and concurrency

Persistence units encapsulate the object-relational mapping to the database. This section is about how they encounter transactions, concurrency, and multiple requests.

Entity managers

Here are some helpful rules about javax.ejb.EntityManager:

  • Prefer to inject EntityManager as a dependency in a Java EE application. Therefore, the application server takes care of its lifecycle and the responsibility to close the persistence unit. Use @PersistenceContext.
  • Do not cache or store in between requests: The EntityManager instance is not thread-safe.
  • The EntityManager instance manually retrieved from EntityManagerFactory must be closed in a retrieval method request for that particular state lest it goes out of scope, escapes, and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required