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

The Problem

The term “Entity Bean” is used loosely—sometimes it means the in-memory Java object, sometimes it means the database record. This confusion makes discussions about entity beans unclear. What’s the difference?

Core Idea

The EJB spec clarifies two distinct concepts:

  1. Entity Bean Instance: The in-memory Java object (an instance of your entity bean class). It’s the “view” into the database.
  2. Entity Bean Data: The actual persistent data stored in the database (the record/row).

The instance loads data from the database (in ejbLoad()), modifies it in memory, and saves it back (in ejbStore()).

How It Works

Database Record (Entity Bean Data)
    ↓ ejbLoad()
In-Memory Object (Entity Bean Instance)
    ↓ business methods modify fields
In-Memory Object (with changes)
    ↓ ejbStore()
Database Record (updated)

Visual Explanation

InstanceVsData Data Entity Bean Data (Database Row) | ID | Owner | Balance | | 1 | Ray | 1000 | Instance Entity Bean Instance (In-Memory Java Object) accountID=1, owner="Ray", balance=1000 Data->Instance 1. ejbLoad() Read from DB Instance->Data 2. ejbStore() Write to DB note Client modifies balance Instance.balance = 2000 Instance->note

Key Properties

  • Instance is temporary: Created when needed, may be pooled/reused for different data
  • Data is permanent: Survives server crashes, lives in database
  • One-to-one mapping: At any moment, one instance represents one data record
  • Container manages sync: ejbLoad() and ejbStore() keep instance and data in sync

Connections

Edge Cases & Gotchas

  • Stale data: If another client modifies the DB directly, in-memory instance has old data (until next ejbLoad())
  • Instance pooling: The same Java instance might represent Ray’s account now, Bob’s account later (container reuses instances)
  • Transparent to client: Client doesn’t know or care about instance vs data distinction—they just call methods