views:

423

answers:

1

Hi. 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

A: 

Are you using Hibernate? I had the same issue with Hibernate but changing to Eclipselink with the same code worked.

javydreamercsw