How do you model business processes and workflow logic in a server-side Java application that can be managed by a container and participate in transactions?
A session bean is a server-side component that represents work being performed for client code. It implements business logic, rules, algorithms, and workflow. Session beans are business process objects—not persistent data objects.
- Client code accesses session beans through the EJB container
- The container intercepts all calls, providing middleware services (security, transactions, concurrency)
- Session beans are non-persistent—they exist only in memory during a client session
- When the client disconnects, the session bean can be destroyed
- Session beans do not survive server or machine crashes
- Non-persistent (in-memory only)
- Short-lived (lifetime of client session)
- Not shared between multiple clients
- Can perform database operations but are not themselves persistent
- Two subtypes: stateful and stateless
- Built from: EJB Container, Session Bean Lifetime, Session Bean Subtypes
- Builds into: Stateful Session Bean, Stateless Session Bean, Session Bean Relationships, Stateless Session Bean Pooling
- Contrasts with: Entity Bean, Message-Driven Bean
- Related: Home Interface, Local Home Interface, EJB Object, Transaction Demarcation, Declarative vs Programmatic Transactions, Don't Rely on ejbRemove()
- Session beans cannot survive application server crashes
- If client times out, container may destroy the session bean
- Do not rely on ejbRemove() for critical cleanup—it may never be called if container crashes