Multiple choice java

Container managed transactions are defined via trans-attributes in the deployment descriptor. When a session bean demarcates the transaction and calls an Entity Bean, what is the best transactional setting for the Entity Bean?

  1. Supports

  2. Never

  3. Required

  4. RequiresNew

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

When a session bean demarcates the transaction (using UserTransaction) and calls an entity bean, the entity bean should have transaction attribute 'Required' to ensure it joins the existing transaction context. 'Supports' would allow it to run non-transactionally, which could cause data inconsistency.

AI explanation

Correct answer: Required. When a session bean already has an active container-managed transaction and calls into an Entity Bean, the Entity Bean should use the 'Required' transaction attribute so its work joins the caller's existing transaction (starting a new one only if none exists) — this preserves atomicity across the call chain. 'Supports' would run the entity bean's methods with or without a transaction (unsafe for consistency), 'Never' would throw an exception since a transaction is already active, and 'RequiresNew' would incorrectly suspend the caller's transaction and start an unrelated new one, breaking the intended atomic unit of work.