3

What happens in following scenario if error occurred in DStateless.method4() or BSession.method2()? I want that CStateless.method3() and DStateless.method4() share the same transaction.

Is it permitted to make such calls in EJB and CDI ?

ASession.method1() (calls)-> CStateless.method3() -> BSession.method2() -> DStateless.method4();

@SessionScoped
class ASession {
   method1();
}

@SessionScoped
class BSession {
   method2();
}

@Stateless
class CStateless {
   method3();
}

@Stateless
class DStateless {
   method4();
}
assylias
  • 321,522
  • 82
  • 660
  • 783
Tony
  • 2,266
  • 4
  • 33
  • 54
  • 1
    In this case they will share the same transaction. The only question is why would you call a sessionscoped bean from a stateless bean – maress Aug 27 '15 at 14:27
  • @maress The main reason is that sessionScoped bean makes some file operations. Another reason is session scoped bean has more informations about what to do. – Tony Aug 27 '15 at 14:58
  • That still does not warrant sessionscoped bean invocation from stateless bean. Do everything in session bean that requires session/request context and then upload the next logic to stateless bean. The session bean can potentially call several stateless beans to finish up its work – maress Aug 27 '15 at 15:24
  • @maress yes session bean can call several stateless beans, but what to do if all calls should be in a single transaction ? – Tony Aug 28 '15 at 06:52

1 Answers1

0

Yes, it's permitted.

Assuming that method1() is not running in a transaction, the transaction boundary will be around method3(). method4() will use the same transaction.

Harald Wellmann
  • 12,615
  • 4
  • 41
  • 63