Entity Beans
Entity Bean
Models data Represents real data objects, such as customer, products, or employees Does not contain business process logic Knows how to persist itself
Features
Long-lived Survive failures View into data store Single Threaded
Entity Bean’s Components
Remote interface
Home interface
Interface to entity beans class on which clients invoke Clients create, find, and destroy entity beans
Bean class
Models persistent data
Entity Bean’s Components
Primary bean class
Unique identifier for your entity bean
Deployment descriptor
Contains entity bean’s properties Properties will be used by the container
Entity Beans
Two ways to persist entity beans:
Bean-Managed Persistent (BMP) Container-Managed persistent (CMP)
BMP
Developer must handle the persistence Developer must write code to take the in-memory data and store them into an underlying data store
CMP
The container/server handles the persistence layer
Creating Entity Bean ejbCreate() Is used to create underlying data May have different parameters Must have a corresponding create() method in home interface Example:
public AccountPK ejbCreate(String accountID, String owner) … public Account ejbCreate(String accountID, String owner) …
Finding Entity Beans – ejbFind() All finders start with ejbFind Must exist at least one called ejbFindByPrimaryKey() May have different names and parameters Example:
public Enumeration ejbFindAllProducts() … public Enumeration findAllProducts() …
Destroying Entity Beans – ejbRemove()
Will remove the database data Has a corresponding remove() method in home interface Will not be called if entity bean times out
Entity Context – setEntityContext()
Represents the environment of the entity bean
getEJBObject()
Returns the EJBObject associated with the entity bean
getPrimaryKey()
Identifies which database data the entity bean is associated with