Chapter 7. EntityManagerFactory
Prev | Part 2. Java Persistence API | Next

## Chapter 7. EntityManagerFactory

The `EntityManagerFactory` creates `EntityManager` instances for application use.

### Note

OpenJPA extends the standard `EntityManagerFactory` interface with the `OpenJPAEntityManagerFactory` to provide additional functionality.

## 1. Obtaining an EntityManagerFactory

Within a container, you will typically use injection to access an `EntityManagerFactory`. There are, however, alternative mechanisms for `EntityManagerFactory` construction.

Some vendors may supply public constructors for their `EntityManagerFactory` implementations, but we recommend using the Java Connector Architecture (JCA) in a managed environment, or the `Persistence` class' `createEntityManagerFactory` methods in an unmanaged environment, as described in Chapter 6, Persistence . These strategies allow vendors to pool factories, cutting down on resource utilization.

JPA allows you to create and configure an `EntityManagerFactory`, then store it in a Java Naming and Directory Interface (JNDI) tree for later retrieval and use.

Prev | Up | Next
2. Non-EE Use | Home | 2. Obtaining EntityManagers