How do you model persistent business data in EJB so that it survives beyond client sessions and can be shared across multiple clients?
An entity bean is a persistent object that represents business data stored in permanent storage (typically a relational database). Entity beans are the “nouns” of EJB—representing things like bank accounts, customers, and products.
- Entity beans have an identity (primary key) that distinguishes them
- They survive server crashes and can live for months or years
- Multiple clients can share the same entity bean
- Lifetime is independent of any client session
- Container can manage persistence (CMP) or bean can manage it (BMP)
- Mapped to database tables via O/R mapping
- Persistent (survives beyond client session)
- Has identity (primary key)
- Shared by multiple clients
- Can be mapped to relational database tables
- Models data, not process or workflow
- Can be accessed and modified by session beans
- Built from: EJB Container, Primary Key, Entity Bean Identity, Entity Bean Instance vs Data, Persistence Concepts
- Builds into: Bean-Managed Persistence, Container-Managed Persistence, Entity Context
- Contrasts with: Session Bean, Message-Driven Bean, Session Bean Lifetime
- Related: Instance Pooling, Finder Methods, ejbLoad(), ejbStore(), ejbCreate(), ejbRemove()
- Related: Entity Bean Transaction Rules, One-to-One Relationship, One-to-Many Relationship, Many-to-Many Relationship, Serialization vs ORM
- Entity beans represent data, not business logic
- Not suitable for complex workflow or algorithms (use session beans for that)
- The difference between entity bean instance and entity bean data is important