1 Reply Latest reply on Jul 17, 2013 9:28 AM by sfcoy

    entityManager.executeUpdate() doesn't rollback when datasource's jta = false in standalone.xml

    joe.chuah

      Hi,

       

      I encountered this issue recently and was just wondering why it happens.

       

      So basically we have a Container Managed Service Bean which does the following

       

      part A: some insert/update statements using entityManager.persist/merge

      part B: some delete statements using javax.persistence.Query.executeUpdate() where the instance of javax.persistence.Query is created by the entityManager

      part C: some insert/update statements using entityManager.persist/merge

       

      if an RuntimeException occurs (I threw 1 myself just to experiment), part A and part C rollsback successfully but part B doesn't

       

      Once I changed jta="true" in the standalone.xml then it rollsback fine.

       

      Thanks in advance for any explanations regarding this.

        • 1. Re: entityManager.executeUpdate() doesn't rollback when datasource's jta = false in standalone.xml
          sfcoy

          In my opinion you should always use JTA in an enterprise java application. I'm not sure there's any good reason to set jta="false".

           

          Furthermore, a container managed entity manager must be a "JTA entity manager" (§7.5 of the Java Persistence API 2.0 specification) and must be associated with a JTA DataSource.

           

          In your example, when you set jta="false" the container managed transaction will not propogate the rollback instructions to the database because it's no longer aware that the database should be participating.