This chapter is for is the Enterprise Bean provider; that is, the person in charge of developing the software components on the server side, and more specifically the Entity Beans.
Note | |
---|---|
In this documentation, the term "Bean" always means "Enterprise Bean." |
An Entity Bean is comprised of the following elements, which are developed by the Enterprise Bean Provider:
The Component Interface is the client view of the bean. It contains all the "business methods" of the bean.
The Home Interface contains all the methods for the bean life cycle (creation, suppression) and for instance retrieval (finding one or several bean objects) used by the client application. It can also contain methods called "home methods," supplied by the bean provider, for business logic that is not specific to a bean instance.
The Primary Key class (for Entity Beans only) contains a subset of the bean's fields that identifies a particular instance of an Entity Bean. This class is optional since the bean programmer can alternatively choose a standard class (for example, java.lang.String)
The bean implementation class implements the business methods and all the methods (described in the EJB specification) allowing the bean to be managed in the container.
The deployment descriptor, containing the bean properties that can be edited at assembly or deployment time.
Note | |
---|---|
According to the EJB 2.0 specification, the "Component Interface and Home Interface" can be either local or remote. Local Interfaces (Home and Component) are to be used by a client running in the same JVM as the EJB component. Create and finder methods of a local (or remote) home interface return local (or remote) component interfaces. An EJB component may have both remote and local interfaces, even if normally only one type of interface is provided. If an Entity Bean is the target of a container-managed relationship (refer to EJB 2.0 persistence), then it must have local interfaces. These elements are described in the following sections. |
An Entity Bean represents persistent data. It is an object view of an entity stored in a relational database. The persistence of an Entity Bean can be handled in two ways:
Container-Managed Persistence: the persistence is implicitly managed by the container; no code for data access is supplied by the bean provider. The bean's state will be stored in a relational database according to a mapping description delivered within the deployment descriptor (CMP 1.1) or according to an implicit mapping (CMP 2.0).
Bean-Managed Persistence: the bean provider writes the database access operations (JDBC code) in the methods of the enterprise bean that are specified for data creation, load, store, retrieval, and remove operations (ejbCreate, ejbLoad, ejbStore, ejbFind..., ejbRemove).
Currently, the platform handles persistence in relational storage systems through the JDBC interface. For both container-managed and bean-managed persistence, JDBC connections are obtained from an object provided at the EJB server level, the DataSource. The DataSource interface is defined in the JDBC 2.0 standard extensions (see http://java.sun.com/products/jdbc/). A DataSource object identifies a database and a means to access it via JDBC (a JDBC driver). An EJB server may propose access to several databases and thus provides the corresponding DataSource objects. DataSources are described in more detail in Chapter 4 Configuring JDBC DataSources.