• ↑↓ to navigate
  • ↵ to open
  • ⟶ to select
  • ⌘ ⌥ ↵ to open in a panel
  • ←→ to navigate
  • esc to dismiss
⌘ '
keyboard shortcuts

The Problem

How do you avoid writing repetitive JDBC/database code for every entity bean?

Core Idea

With container-managed persistence (CMP), the EJB container automatically handles all database operations. The developer writes no JDBC code—the container generates SQL statements for create, read, update, and delete operations.

How It Works

  • Developer strips entity bean of any persistence logic
  • Developer uses vendor tools to define O/R mappings (how bean fields map to database columns)
  • At deployment time, container generates the data access code
  • Container automatically performs INSERT, UPDATE, DELETE, and SELECT operations
  • Mapping can be done at deployment time, making beans storage-independent

Key Properties

  • Container handles all persistence automatically
  • No JDBC code in the bean
  • O/R mapping defined at deployment time
  • Storage-independent—can switch databases without changing bean code
  • Reduces bean size significantly

Visual Explanation

Container_Managed_Persistence A Container Managed Pe Input B Container Managed Pe Core Mechanism A->B triggers C Container Managed Pe Output B->C produces

Semantic Network

semantic_Container_Managed_Persistence THIS Container Managed Pe REL1 Related Concept THIS--REL1 related REL2 Builds Into THIS--REL2 builds into

Edge Cases & Gotchas

  • Less control over exact SQL generated
  • Vendor-specific tools may be required for mapping
  • May not support all database features