1 2 Previous Next 18 Replies Latest reply on Sep 20, 2018 2:21 AM by Sergiu Pienar

    WildFly 14 + Hibernate 5.3.6 results in Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query

    Sergiu Pienar Expert

      I'm using WildFly 14 together with the Hibernate version of 5.3.6 that is bundled with the server.

      I've been having some issues with this hibernate version because it seems to have changed the behavior on transaction boundaries.

      The latest exception I'm getting is:

       

      Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
              at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1586)
              at com.dao.DAOHelper.executeUpdate(DAOHelper.java:813)

       

      The DAOHelper's executeUpdate method is called form an EJB annotated with @TransactionAttribute(TransactionAttributeType.REQUIRED).

      The executeUpdate method's body is:

       

      protected static int executeUpdate(final SessionFactory hibernateSessionFactory, final String queryString,
      final Map<string, object> parameterMap) {
      
      if (!StringTools.isValidString(queryString)) {
      throw new IllegalArgumentException("The query name is missing");
      }
      if (hibernateSessionFactory == null) {
      throw new IllegalArgumentException("SessionFactory is null!");
      }
      
      Session sess = null;
      try {
      sess = hibernateSessionFactory.openSession();
      int count = 0;
      
      Query query = sess.createQuery(queryString);
      
      if (parameterMap != null) {
      query.setProperties(parameterMap);
      }
      
      count = query.executeUpdate();
      
      sess.flush();
      hibernateSessionFactory.getCache().evictQueryRegions();
      
      return count;
      } finally {
      if (sess != null) {
      sess.close();
      }
      }
      }

       

      All this was working fine with WildFly 13 and Hibernate 5.1.14 so I'm expecting this to be a configuration issue.


      While I understand the exception and that the container expects me to run updates / deletes in a transactional context I was hoping that this is achieved in a CMT when I'm annotating the EJB with @TransactionAttribute(TransactionAttributeType.REQUIRED) as it has been since forever.

        1 2 Previous Next