Skip to content

Instantly share code, notes, and snippets.

Created July 10, 2015 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e4be34bff32545e25ba1 to your computer and use it in GitHub Desktop.
Save anonymous/e4be34bff32545e25ba1 to your computer and use it in GitHub Desktop.
@ApplicationScoped
public class PersistenceUnit {
@javax.persistence.PersistenceUnit(unitName = "default")
private EntityManagerFactory entityManagerFactory;
@Produces
@RequestScoped
public EntityManager create() {
return entityManagerFactory.createEntityManager();
}
public void dispose(@Disposes final EntityManager entityManager) {
if (entityManager.isOpen()) {
entityManager.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment