Can I create an EntityManager
from EntityManagerFactory
outside a bean. If so, how would I do it?
views:
52answers:
1
+1
A:
In a non-managed environment (this is what you mean by outside a bean, right?), then you typically use:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("MyPu");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin()
...
em.getTransaction().commit();
emf.close();
Check the other factory method allowing to pass properties as parameter (they will override any values that may have been configured elsewhere): Persistence.createEntityManagerFactory(String, Map)
.
See also
Pascal Thivent
2010-06-09 16:17:08