1 Reply Latest reply on Jan 23, 2013 6:20 AM by mbohnen

    CMT, EJB 3.1 and JBoss 7.1.1

    mbohnen Newbie

      Hi all!

       

      One more question from my side ...

      If I have a stateless service (Stateless Session Bean: SLSB) as facade (say GlobalService) which methods invokes several other services (again SLSBs, say FooService and BarService):

       

       

          @Stateless

          @Remote(GlobalService.class)

          @TransactionManagement(TransactionManagementType.CONTAINER)

          public class GlobalServiceBean implements GlobalService{

                private Logger log = Logger.getLogger(GlobalServiceBean.class);

       

                @EJB

                private FooService fooService;

       

       

                @EJB

                private BarService barService;

       

                public void createFoo(Foo foo, Bar bar) throws WrappedGoneBadException{

                          fooService.create(foo); // bang here

                    barService.create(bar); // no bang here

       

       

              

      All methods at FooService (as well as BarService, which looks pretty much the same) annotated as requiring a new transaction:

       

       

          @Stateless

          @Remote(FooService.class)

          @TransactionManagement(TransactionManagementType.CONTAINER)

          @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

          public class FooServiceBean implements FooService{

             public Foo save(Foo foo){

               ... // exception here

       

       

      Presumed FooServiceBean persists some objects of type 'Foo' and during this, an unchecked exception (DuplicateKeyException) will be thrown does this affect the 'surrounding' transaction to be rolled back or will it be ignored and Bar will be created? My initial thought has been, it will not affect the 'outer' transaction but Jboss proved me wrong ... All I could find on the internet says, that REQUIRES_NEW will start a new transaction which will not affect the 'outer' transaction.

       

      Then I tried to throw an ApplicationException using rollback = false, as expected, Bar was saved. Once I changed it to rollback = true Bar wasn't saved.

       

      Is this the behaviour one can expect, am I wrong and if so ... how to isolate the both of them: Foo to cause an exception and obviously not saved but Bar to be saved?

       

       

      Thx in advance