8.10.2 javax.persistence.EntityManagerFactory interface
This section describes the interface definition and the notes on the javax.persistence.EntityManagerFactory interface.
- Organization of this subsection
(1) Definition of the interface
package javax.persistence; /** * The EntityManagerFactory interface is used * to obtain the application-managed EntityManager by the application. * When the application ends the use of EntityManagerFactory, * the application must close EntityManagerFactory. * After EntityManagerFactory is closed, * all EntityManagers created from EntityManagerFactory are * treated as closed. */ public interface EntityManagerFactory { /** * Creates a new EntityManager. * Whenever this method is invoked, a new EntityManager instance * is returned. * The isOpen method of EntityManager returned by this method returns * true. * @return New EntityManager */ public EntityManager createEntityManager() ; /** * A new EntityManager is created by using the specified property * map. * Whenever this method is invoked, a new EntityManager instance * is returned. * The isOpen method of EntityManager returned by this method returns * true. * @param map Map storing the EntityManager properties * @return New EntityManager */ public EntityManager createEntityManager(Map map) ; /** * Closes factory and releases all the resources * stored in factory. * After factory is closed, if method other than isOpen is invoked, * IllegalStateException is thrown. The isOpen method returns * false. * If EntityManagerFactory is closed, all EntityManagers created * from factory are also treated as closed. */ public void close() ; /** * Returns whether factory is open. * @return True until factory is closed */ public boolean isOpen() ; }
(2) Notes
-
You can include vendor-specific properties of the JPA provider in the map passed to createEntityManager. The properties that cannot be recognized by the JPA provider are ignored.
-
With the EJB specifications, the following methods can invoke the EntityManagerFactory methods in the Stateless Session Bean:
-
Life cycle callback method (PostConstruct and PreDestroy)
-
Business method of the business interface or component interface
-
Business method
-
Interceptor method
-
Timeout callback method
The EntityManagerFactory methods cannot be invoked with the constructor and the setter method (including the setSessionContext method) of the DI.
-
-
With the EJB specifications, the following methods can invoke the EntityManagerFactory methods in the Stateful Session Bean:
-
Life cycle callback method (PostConstruct and PreDestroy)
-
Business method of business interface or component interface
-
Business method
-
Interceptor method
-
The afterBegin and beforeCompletion methods of SessionSynchronization.
The EntityManagerFactory methods cannot be invoked with the constructor, the setter method of the dependency injection, and the afterCompletion method of SessionSynchronization.
-