public class EntityManagerFactoryProducer extends Object
Built in support for injecting EntityManagerFactories into own beans.
The injection point must use the Qualifier PersistenceUnitName
to express the desired persistence unit name.
The EntityManagerFactory for the given persistence unit will be produced as @Dependent scoped. It can be used to easily implement own EntityManagerProviders as shown in the following example which provides a producer according to the entitymanager-per-request design pattern:
@ApplicationScoped
public class SampleEntityManagerProducer {
@Inject
@PersistenceUnitName("testPersistenceUnit")
private EntityManagerFactory emf;
@Produces
@RequestScoped
public EntityManager createEntityManager() {
return emf.createEntityManager();
}
public void closeEm(@Disposes EntityManager em) {
em.close();
}
}
| Constructor and Description |
|---|
EntityManagerFactoryProducer() |
| Modifier and Type | Method and Description |
|---|---|
javax.persistence.EntityManagerFactory |
createEntityManagerFactoryForUnit(javax.enterprise.inject.spi.InjectionPoint injectionPoint) |
Copyright © 2011-2013 The Apache Software Foundation. All Rights Reserved.