How do you have full control over how entity beans interact with the database?
With bean-managed persistence (BMP), the developer writes explicit JDBC code (or uses other database APIs) in the entity bean to handle all database operations. The developer is responsible for implementing ejbCreate(), ejbRemove(), ejbFind(), and other data access methods.
- Developer writes JDBC code in bean methods
- ejbCreate() inserts data into the database
- ejbRemove() deletes data from the database
- Finder methods (ejbFindByPrimaryKey, etc.) query the database
- Container calls these methods, but developer implements the SQL logic
- Full control over database operations
- Developer writes JDBC code
- More flexibility than CMP
- More code to maintain
- Container still provides middleware services
- Built from: Entity Bean, JDBC
- Builds into: ejbCreate(), ejbRemove(), Finder Methods, ejbLoad(), ejbStore(), One-to-One Relationship, One-to-Many Relationship, Many-to-Many Relationship
- Contrasts with: Container-Managed Persistence
- Related: getPrimaryKey(), Instance Pooling, Primary Key Class, Session Bean Relationships
- More error-prone than CMP
- Database-specific code may reduce portability
- Must handle transactions manually in some cases