Application-Managed entityManager work, but Container-Managed Entity Manager doesn't. Why?

橙三吉。 提交于 2019-12-14 03:04:57

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!