The following exception thrown for Spring Batch application:
19:12:40,083 ERROR main AbstractStep:213 - Encountered an error executing the step
javax.persistence.TransactionRequiredException: Executing an update/delete query
Code,where named query used:
entityManagerFactory.createEntityManager()
.createNamedQuery("removeQuery").executeUpdate();
also tried to wrap this code in begin and commit methods of EntityTransaction object and, didn't help:
EntityManager em = entityManagerFactory.createEntityManager();
EntityTransaction transaction = em.getTransaction();
transaction.begin();
entityManagerFactory.createEntityManager()
.createNamedQuery("removeQuery").executeUpdate();
transaction.commit();
开发者_如何学Goem.close();
entityManagerFactory.close();
thank you in advance
You don't use same entity manager to create your transaction and to create your query.
Replace
entityManagerFactory.createEntityManager()
.createNamedQuery("removeQuery").executeUpdate();
by
em.createNamedQuery("removeQuery").executeUpdate();
精彩评论