Search code examples
ejb-3.0java-ee-5

Operations allowed in stateless session bean's business methods


Given a Stateless Session Bean with a Local Business Interface and CMT (Container Managed Transaction). All methods of the SLSB have Transaction Attribute set to "REQUIRED".

The Bean also has an injected field sessionContext of type SessionContext.

The question is: "Which two operations are allowed in a bean business method?"

According to EJB 3.0 Core Specification, Chapter 4 Table 2:

SessionContext methods: getBusinessObject,getEJBHome, getEJBLocalHome, getCallerPrincipal, isCallerInRole, getRollbackOnly, setRollbackOnly, getEJBObject, getEJBLocalObject, getTimerService,getInvokedBusinessInterface, lookup JNDI access to java:comp/env

Since this is a question of a simulator for SCBCD (1z0-860) Certification for Java EE 5, the provided answer is:

  • sessionContex.setRollbackOnly()
  • sessionContext.getBusinessObject()

Other two possible options were "sessionContext.getEJBObject" and "sessionContext.getEJBLocalObject".

Having the SLSB a Business Local Interface, my second choice, after setRollbackOnly was to call getEJBLocalObject which actually is not the right answer.

Is the asnwer provided by simulator correct? If yes: Anyone can help me to better understand this scenario?

Regards, Pierluigi


Solution

  • Of the given options:

    1. sessionContext.setRollbackOnly - Can be called because the bean uses container-managed transactions
    2. sessionContext.getBusinessObject - Can be called because the bean has a business interface
    3. sessionContext.getEJBObject - Cannot be called because only beans that have a remote component view can call this method
    4. sessionContext.getEJBLocalObject - Cannot be called because only beans that have a local component view can call this method