• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Enterprise beans perform mission-critical tasks that must be reliable and robust. Without transactions, partial failures (e.g., debiting one account but not crediting the other) lead to data inconsistency. EJB abstracts low-level transaction systems so developers focus on business logic.

Core Idea

Transactions in EJB provide ACID properties (Atomicity, Consistency, Isolation, Durability) for enterprise bean operations. The EJB container abstracts the underlying transaction system — beans only vote on commit/abort, never interact directly with transaction managers.

How It Works

  1. EJB uses flat transactions (all-or-nothing, no nested transactions in EJB spec)
  2. Transaction boundaries are demarcated via: Programmatic (BMT), Declarative (CMT), or Client-Initiated
  3. Container handles: begin, commit, rollback — bean signals success/failure
  4. Entity beans: ejbLoad() acquires locks → business methods run → ejbStore() writes and releases locks (all within one transaction)
  5. Transaction spans entire set of operations or per-method depending on demarcation style

Visual Explanation

G Bean Enterprise Bean business logic Container EJB Container transaction handling Bean->Container votes commit/abort TX Transaction (ACID properties) Container->TX begin/commit/rollback DB Database TX->DB consistent operations

Key Properties

  • ACID: Atomicity (all-or-nothing), Consistency (valid state), Isolation (concurrent tx don’t interfere), Durability (committed data survives crashes)
  • EJB uses flat transactions (nested transactions NOT supported)
  • Container abstracts low-level transaction system (bean never touches transaction manager)
  • Entity beans load/store per transaction, not per method call
  • Transaction attributes (in deployment descriptor) control when transactions start/end

Connections

Edge Cases & Gotchas

  • Nested transactions are NOT supported in EJB (despite being described in the book)
  • Entity beans transaction spans ejbLoad → methods → ejbStore (not per individual method)
  • If each entity bean method is a separate transaction, performance suffers (too many DB reads/writes)
  • Client-initiated transactions over network have higher rollback rates (network failures)