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

The Problem

When a client on a different machine wants to call a method on an Enterprise Bean, how does the remote call actually happen? Direct object references from one JVM cannot be used in another JVM — memory addresses are meaningless across machines. We need an abstraction layer that handles remote communication transparently.

Core Idea

The EJB Object is a container-generated stub that acts as a proxy between the client and the actual Enterprise Bean. It wraps the bean, intercepts method calls, and handles all the RMI communication under the hood.

How It Works

  1. Container automatically generates the EJB Object when the bean is deployed
  2. Client never accesses the bean directly — always goes through the EJB Object
  3. When client calls a method, EJB Object:
    • Serializes the method parameters
    • Sends the request over network (using RMI-IIOP)
    • Forwards to actual bean instance
    • Serializes the response
    • Returns to client
  4. The EJB Object also handles:
    • Transaction demarcation
    • Security checks
    • Life cycle management

The client holds a reference to the EJB Object, not the actual bean.

Visual Explanation

G Client Client EJB Object EJB Object Client->EJB Object 1. Method call EJB Object->Client 4. Response Enterprise Bean Enterprise Bean EJB Object->Enterprise Bean 2. Delegates to bean Enterprise Bean->EJB Object 3. Returns result

Key Properties

  • Container-generated: Automatically created by the EJB container at deployment time
  • Remote proxy: Handles all network communication transparently
  • Thread-safe: Manages concurrency for the bean
  • Transaction-aware: Can automatically start/commit/rollback transactions
  • Security-aware: Enforces role-based access before delegating to bean

Connections

Edge Cases & Gotchas

  • Client never holds direct reference to bean — always through EJB Object
  • If container fails, EJB Object cannot communicate with bean
  • EJB Object pooling is possible for stateless beans, but each stateful bean has its own EJB Object
  • The “EJB Object” is conceptually similar to a Stub in RMI