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();
em.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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With