Why Do Two Methods Of A Stateless Session EJB 3.0 Use The Same Transaction? (Doc ID 790455.1)

Last updated on NOVEMBER 05, 2016

Applies to:

Oracle Containers for J2EE - Version 10.1.3.0.0 to 10.1.3.4.0 [Release AS10gR3]
Oracle TopLink - Version 10.1.3.3 to 10.1.3.5 [Release AS10gR3]
Information in this document applies to any platform.

Goal

With an EJB defined as

@Stateless(name = "WebService")
@TransactionManagement(value=TransactionManagementType.CONTAINER)
public...TestEJB...{

  @PersistenceContext(unitName = "Service")
  private EntityManager em;

  @Resource
  SessionContext sessionCtx;

  @TransactionAttribute(value=REQUIRES_NEW)
  public ...method1(EntityManager em,...) ..{
    ...
  }

  @TransactionAttribute(value=REQUIRES_NEW)
  public ...method2() ..{
    try {
        ...
    } catch (Exception e) {
      sessionCtx.setRollbackOnly();
      method1(em,...);
    }
  }
}


why do method1 and method2 run under the same transaction  (method 1 is called by method 2) ?

Solution

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms