Chapter 8.  Deployment

Table of Contents

1. Factory Deployment
1.1. Standalone Deployment
1.2. EntityManager Injection
2. Integrating with the Transaction Manager
3. XA Transactions
3.1. Using OpenJPA with XA Transactions

OpenJPA deployment includes choosing a factory deployment strategy, and in a managed environment, optionally integrating with your application server's managed and XA transactions. This chapter examines each aspect of deployment in turn.

1.  Factory Deployment

OpenJPA offers two EntityManagerFactory deployment options.

1.1.  Standalone Deployment

The JPA Overview describes the javax.persistence.Persistence class. You can use Persistence to obtain EntityManagerFactory instances, as demonstrated in Chapter 6, Persistence . OpenJPA also extends Persistence to add additional EntityManagerFactory creation methods. The org.apache.openjpa.persistence.OpenJPAPersistence class Javadoc details these extensions.

After obtaining the factory, you can cache it for all EntityManager creation duties. OpenJPA factories support being bound to JNDI as well.

1.2.  EntityManager Injection

Java EE application servers allow you to inject entity managers into your session beans using the PersistenceContext annotation. See your application server documentation for details.