• Register
0 votes

Problem :

I am getting bellow error while  using hibernate JPA with spring and mongodb and running my application on Glassfish-4.0.

javax.persistence.transactionrequiredexception: executing an update/delete query

by (6.9k points)  

1 Answer

0 votes


I was simply creating the native query from the persistence EntityManager to perform the 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. By just doing it did not change my error.

I then tried use of application managed entity managers and not container managed and that was joinTransaction().

Kept @Transactional for decorating the method and then called joinTransaction() on EntityManager object just prior to calling query.executeUpdate() and my native query update worked.

Further Readings:


by (36.1k points)  
edited by