...
Code Block |
---|
| java |
---|
| java |
---|
title | Producer for a @TransactionScoped entity manager |
---|
|
public class DataBaseProducer
{
@PersistenceContext(unitName="default")
private EntityManager entityManager;
@Produces
@TransactionScoped
public EntityManager createEntityManager()
{
return this.entityManager;
}
public void dispose(@Disposes EntityManager entityManager)
{
if(entityManager.isOpen())
{
entityManager.close();
}
}
}
|
ConfigurableDataSource (since v1.0.2)
Configuring the data connection properties in JPA projects in pure Java EE is always a painful task. Directly configuring the JDBC driver class and database credentials in the persistence.xml is a no-go.
Configuring a DataSource via JNDI sounds good at the first glance, but has serious flaws:
...