1 Reply Latest reply on Feb 12, 2018 8:36 AM by Michal Krasny

    @Transactional does not work in JBoss module

    Michal Krasny Newbie

      Hello,

       

      in our project we try do split our application to JBoss  modules. I prepared a sample application to describe my problem:

       

      There is a Maven module main-app, which is distributed as  a war file, which contains class MyController.java. This application uses a module with a service TransactionalService.java. The TransactionalService has a public method annotated by javax.transaction.Transactional which checks if there is "com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptor" on stack trace, i.e. if the code of the method is in transaction or not. This method returns true (@Transactional works) only if the @Transactional was used in the main app, see class DummyClassWithTransactional. If it is commented out, the @Transactional in module does not work, if it's present, then it works.

       

      It was tested on  Wildfly 11.0.

       

      Is this is an intended behavior or am I missing something? Main application should not know the implementation of modules so I'd like to use the transactions (and any other AOP behavior) transparently without using the annotations in the main application.

       

      See below for mentioned classed and attached zip file for whole demo application.

       

      Thank you,

       

      Michal

       

      ///////MAIN APP///////////

       

      package com.mk.transaction;

       

      import lombok.extern.slf4j.Slf4j;

       

      import javax.inject.Inject;

      import javax.ws.rs.GET;

      import javax.ws.rs.Path;

       

      @Slf4j
      @Path("/")

      public class MyController {

       

         @Inject
         private TransactionalService transactionalService;

       

         @GET
        @Path("/testTransactional")

         public String testTransactional() {

        String result = transactionalService.testTransaction();

         log.info("Transactional works: {}", result);

         return result + "\n";

        }

      }

       

       

       

      package com.mk.transaction;

       

      import javax.transaction.Transactional;

       

      //if uncommented, the @Transactional annotation in module will start working
      //@Transactional
      public class DummyClassWithTransactional {

       

      }

       

       

       

       

       

      ///////MODULE///////////

       

      package com.mk.transaction;

       

      import lombok.extern.slf4j.Slf4j;

       

      import javax.transaction.Transactional;

      import java.util.Arrays;

       

      @Slf4j
      public class TransactionalService {

       

         @Transactional()

         public String testTransaction() {

         return String.valueOf(Arrays.stream(Thread.currentThread().getStackTrace()).map(StackTraceElement::getClassName).anyMatch(className -> className.contains("com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptor")));

        }

      }

       

       

      /////////module.xml///////////////////////

       

      <?xml version="1.0" encoding="UTF-8"?>
      <module xmlns="urn:jboss:module:1.0"
         name="com.mk.module">

       

       

         <dependencies>

         <module name="javax.transaction.api"/>

         </dependencies>

       

         <resources>

         <resource-root path="logback-classic-1.1.7.jar"/>

         <resource-root path="logback-core-1.1.7.jar"/>

         <resource-root path="lombok-1.16.6.jar"/>

         <resource-root path="slf4j-api-1.7.20.jar"/>

         <resource-root path="wildfly-transactions-module-sample-module-1.0-SNAPSHOT.jar"/>

         </resources>

       

       

      </module>