Which method cannot be called by a stateful session bean using bean-managed transactions?

  1. getUserTransaction()

  2. getRollbackOnly()

  3. getStatus()

  4. None of these


Correct Option: B

AI Explanation

To answer this question, we need to understand the concept of bean-managed transactions in stateful session beans.

A stateful session bean is a type of Enterprise JavaBean (EJB) that maintains state or conversational context with the client. Bean-managed transactions (BMT) are a transaction management mechanism in EJB where the bean itself is responsible for managing the transaction boundaries.

In bean-managed transactions, the stateful session bean has control over the transaction flow and can start, commit, or rollback transactions explicitly.

Now let's go through each option to understand which method cannot be called by a stateful session bean using bean-managed transactions:

Option A) getUserTransaction() - This method returns the UserTransaction object, which allows the bean to control the transaction flow. Therefore, a stateful session bean can call this method.

Option B) getRollbackOnly() - This method is used to check if the current transaction has been marked for rollback. However, in bean-managed transactions, the stateful session bean is responsible for managing the transaction boundaries. Therefore, it cannot call this method to check the rollback status. Hence, this option is correct.

Option C) getStatus() - This method returns the current status of the transaction. In bean-managed transactions, the stateful session bean can call this method to check the status of the transaction.

Option D) None of these - This option is incorrect because option B (getRollbackOnly()) cannot be called by a stateful session bean using bean-managed transactions.

Therefore, the correct answer is B) getRollbackOnly(). This method cannot be called by a stateful session bean using bean-managed transactions.

Find more quizzes: