public interface EntityManagerProvider
extends javax.inject.Provider<javax.persistence.EntityManager>
EntityManager.
Even though this class extends the Provider interface it is not bound as a provider of
EntityManager. The reason for this is that the EntityManager objects do have a
life cycle and should therefore not be stored in instance/member variables.
The UnitOfWork defines the life cycle of the EntityManager. An entity manager
will be created when the unit of work is started. It is open and valid for use during the entire
unit of work. When the unit of work ends the entity manager is closed and can no longer
be used.
It is a good practice to store this provider in a instance/member variable and only obtain an
EntityManager instance in a method where it is used. This ensures that the method always
has access to a valid EntityManager.
The EntityManagerProvider is thread save.| Modifier and Type | Method and Description |
|---|---|
javax.persistence.EntityManager |
get() |
javax.persistence.EntityManager get()
throws IllegalStateException
get in interface javax.inject.Provider<javax.persistence.EntityManager>EntityManager.IllegalStateException - if UnitOfWork.isActive() returns false.Copyright © 2013–2014 The Apache Software Foundation. All rights reserved.