When you use JTA
you can not use the traditional way to access the EntityManager
, i.e.:
EntityManagerFactory factory = Persistence.createEntityManagerFactory(persistence_unit);
or
@PersistenceUnit(unitName="persistence_unit")
private EntityManagerFactory factory;
EntityManager entityManager = factory.createEntityManager();
EntityTransaction entityTransaction = entityManager.getTransaction();
The above only works if you have in persistence.xml
the
transaction-type="RESOURCE_LOCAL";
When using JTA, it is being specified that the container is the one that will provide the EntityManager
, so the following should be used:
@PersistenceContext(unitName="persistence_unit")
private EntityManager entityManager;
And the container is responsible for injecting it.
If you want to solve your error, and do not need multiple contexts, simply change the persistence.xml
de
transaction-type="JTA"
a
transaction-type="RESOURCE_LOCAL"
More info ..