A transactional client receives TransactionRolledBackException from a call to a method on an entity bean. What could be the possible reason(s) for this?

  1. The bean method is throwing a checked exception and is configured with a transaction attribute of "Required".

  2. The bean method is throwing an unchecked exception and is configured with a transaction attribute of "Required".

  3. The bean does not throw an exception but is configured with a transaction attribute of "Mandatory".

  4. The bean method is throwing an unchecked exception and is configured with a transaction attribute of "Requires New".


Correct Option: B

AI Explanation

To answer this question, you need to understand the possible reasons for receiving a TransactionRolledBackException from a call to a method on an entity bean. Let's go through each option to understand why it is correct or incorrect:

Option A) The bean method is throwing a checked exception and is configured with a transaction attribute of "Required". This option is incorrect because a checked exception alone would not cause a TransactionRolledBackException. A TransactionRolledBackException is typically thrown when an unchecked exception occurs during a transaction.

Option B) The bean method is throwing an unchecked exception and is configured with a transaction attribute of "Required". This option is correct because if the bean method throws an unchecked exception (such as a RuntimeException) and is configured with a transaction attribute of "Required", it indicates that the transaction should be rolled back.

Option C) The bean does not throw an exception but is configured with a transaction attribute of "Mandatory". This option is incorrect because the TransactionRolledBackException is typically thrown when an exception occurs during a transaction. If the bean does not throw an exception, it should not result in a TransactionRolledBackException.

Option D) The bean method is throwing an unchecked exception and is configured with a transaction attribute of "Requires New". This option is incorrect because the "Requires New" transaction attribute creates a new transaction for each method invocation, and it does not affect the outcome of the current transaction.

The correct answer is Option B. The bean method throwing an unchecked exception and being configured with a transaction attribute of "Required" can result in a TransactionRolledBackException.

Find more quizzes: