6.8. Key Point Summary

This chapter introduces entity beans and Bean-Managed Persistence (BMP). The EJB container provides services to keep the entity bean synchronized with the underlying database, as well as providing support for transactions. The EJB container manages the life cycle of entity beans, keeping them activated for efficient access by clients.

Although entity beans and session beans have similar structure (they both have home/local home and remote/local interfaces and bean implementations), entity beans and session beans are quite different in the roles they occupy.

  • An entity bean models persistent business data. A session bean models a business process and is not persistent.

  • An entity bean's create() method inserts data into an underlying database. A session bean's create() method only instantiates a bean instance.

  • An entity bean has finder methods that locate records from an underlying database to instantiate a bean instance. A session bean has no equivalent process.

  • An entity bean has home methods that provide services not tied to a particular record, but can be applied to the database as a whole. You could use a session bean business method to provide this same kind of service.

  • An entity bean's business methods provide setter and getter routines to update or obtain persistent variables. These methods are purely data driven. A session bean's business method provides a business service (a process).

  • Entity beans have unique primary keys that map to primary keys in the underlying database.

Additionally, we've encountered the following important topics with entity beans.

  • A bean developer may not be able to take advantage of CMP and will therefore have to use BMP.

  • A finder method returns an entity bean instance (or a collection) to the client , but the corresponding ejbFindXXX() method returns a primary key (or a collection of primary keys) to the container.

  • A finder method that returns a single object throws an ObjectNotFoundException if that primary key is not in the underlying database. A finder method that returns a collection returns an empty collection if no matching records exist.

  • An entity bean's ejbCreate() method performs database inserts. The ejbFindXXX() methods perform database selects. The ejbRemove() method performs database deletes.

  • The finder methods must specify FinderException in their throws clauses.

  • A dirty flag minimizes database updates in ejbStore() and will help optimize entity beans.

  • Use the Session Facade Pattern to access entity beans with local interfaces. This reduces the number of remote calls to the entity bean and improves performance.

  • Encapsulate business processes in the session facade and use a single transaction for multiple-step entity bean updates.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.116.43