问题
I develop client-server application with JavaEE. I have a stateless bean AuthenticateEJB. It works fine, database entry refreshs when I use Application-Managed Entity Manager (package and import statements omitted for simplifying):
@PersistenceUnit(unitName = "horses_unit")
EntityManager em;
user.setToken("PapaToken");
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("horses_unit");
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.merge(user);
tx.commit();
em.close();
emf.close();
but nothing happens when I use Container-Managed Entity Manager:
@PersistenceContext(unitName = "ForthDynamicWebProject")
EntityManager em;
user.setToken("PapaToken");
em.merge(user);
Here is my persistence.xml file (some code omitted for simplifying):
<persistence-unit name="horses_unit" transaction-type = "RESOURCE_LOCAL">
<persistence-unit name="ForthDynamicWebProject" transaction-type = "JTA">
Why I can't write to database with Container-Managed Entity Manager? Where do I make mistakes?
来源:https://stackoverflow.com/questions/49118188/application-managed-entitymanager-work-but-container-managed-entity-manager-doe