开发者

"Executing an update/delete query" exception for @NamedQuery doing REMOVE

开发者 https://www.devze.com 2023-01-01 22:31 出处:网络
The following exception thrown for Spring Batch application: 19:12:40,083 ERROR main AbstractStep:213 - Encountered an error executing the step

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消