TransactionRequiredException Executing an update/delete query
I am not sure if this will help your situation (that is if it stills exists), however, after scouring the web for a similar issue.
I was creating a native query from a persistence EntityManager to perform an update.
Query query = entityManager.createNativeQuery(queryString);
I was receiving the following error:
caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
Many solutions suggest adding @Transactional to your method.Just doing this did not change the error.
Some solutions suggest asking the EntityManager for a EntityTransaction
so that you can call begin and commit yourself.This throws another error:
caused by: java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead
I then tried a method which most sites say is for use application managed entity managers and not container managed (which I believe Spring is) and that was joinTransaction()
.
Having @Transactional
decorating the method and then calling joinTransaction()
on EntityManager object just prior to calling query.executeUpdate()
and my native query update worked.
I hope this helps someone else experiencing this issue.
as form the configuration xml it is clear that you are going to use spring based transaction. Please make sure that the import which you are using for @Transactional is "org.springframework.transaction.annotation.Transactional"
in your case it might be "javax.transaction.Transactional"