Ejemplo:
private static EntityManagerFactory emf;
public static final ThreadLocal
public static EntityManagerFactory getEntityManagerFactory() {
if (emf == null) {
emf = Persistence.createEntityManagerFactory("actionBazaar");
}
return emf;
}
public static EntityManager getEntityManager() {
EntityManager entityManager = _threadLocal.get();
if (entityManager == null) {
entityManager = emf.createEntityManager();
_threadLocal.set(entityManager);
}
return entityManager;
}
No hay comentarios:
Publicar un comentario