2 Replies Latest reply on Oct 25, 2018 4:10 PM by sganta07

    Wildfly11 not rolling back EJB 2 (CMT) Transactions

    sganta07

      we are migrating from JBoss 6.1.0 to wildfly-11.0.0.Final and we are using EJB 2.0 with container managed transactions. With the wildfly we are experiencing the EJB transaction rollback issue whenever there is an exception.The transaction is being committed even though there is an exception.

      I have modified the standalone.xml to add jta="true" to datasource as shown below.

              <subsystem xmlns="urn:jboss:domain:datasources:5.0">

                      <datasource jta="true" jndi-name="java:/xxxDS" pool-name="xxxDS" enabled="true" use-java-context="true">

                          <connection-url>jdbc:oracle:thin:@xxxxx:1522:xxxxx</connection-url>

                          <driver>oracle</driver>

                          <security>

                              <user-name>xxxxx</user-name>

                              <password>xxxxx</password>

                          </security>

                      </datasource>

      Also I have tried rollback=true as shown below in ejb-jar.xml with no success.

             <application-exception>

              <exception-class>java.lang.Exception</exception-class>

              <rollback>true</rollback>

              <inherited>true</inherited>

          </application-exception>

      Where as I manually rollback the trasaction on exception using sessionContext.setRollbackOnly() in session bean, then the transaction is being rolled back.

       

      please let me know if there is a way we can rollback automatically on Exception without manually doing it?

      Thanks in advance.

        • 1. Re: Wildfly11 not rolling back EJB 2 (CMT) Transactions
          grossmeister_g

          Hi,

           

          what kind of exception are we talking about? You need to distinguish between checked and unchecked exceptions. If it is a unchecked exception (e.g. RuntimeException) the container will do the rollback automatically. If it is a checked Exception (e.g. public void perform() throws IOException), then no rollback is performed.

           

          This one might help you find further informations:

          java - EJB3 transaction rollback - Stack Overflow

          P.S. I saw you're talking about EJB2. I'm only familiar with EJB3 but i suppose the container might behave similarly.

          1 of 1 people found this helpful
          • 2. Re: Wildfly11 not rolling back EJB 2 (CMT) Transactions
            sganta07

            Hi,

            Thanks for your reply. when we throw an unchecked exception (RuntimeException) such as EJBException the container is rolling back the transaction. where as if we throw a checked exception the container is not rolling back even though we have jta='true' in datasource.xml.

            please let me know whether I am missing anything here.

            Thanks in advance