javax.persistence.TransactionRequiredException: Executing an update/delete query in Hibernate
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 7.2
- Hibernate 5.3
Issue
-
Executing an "update" query outside of a transaction using the code below was possible in Hibernate 5.1:
entityManager.createNativeQuery("delete from Employee").executeUpdate(); -
After moving from JBoss EAP 7.1 / Hibernate 5.1 to JBoss EAP 7.2 / Hibernate 5.3, encountering the failure below:
... javax.persistence.TransactionRequiredException: Executing an update/delete query at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1586) ...
Resolution
This issue1 is resolved in This content is not included.EAP 7.2 cumulative patch (CP) 1 and later releases with support of the hibernate.allow_update_outside_transaction property discussed in the Content from github.com is not included.migration document for Hibernate 5.1 users.
Root Cause
This is a known defect (Content from hibernate.atlassian.net is not included.HHH-13262).
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.