| CONTENTS | PREV | NEXT | INDEX | Designing Enterprise Applications with the J2EETM Platform, Second Edition |
Distributed enterprise applications require a number of common services. These include maintaining state, operating on shared data, participating in transactions, servicing a large number of clients, providing remote access to data, and controlling access to data. The middle tier of enterprise computing has evolved as the ideal place to provide these services. The J2EE platform promotes the Enterprise JavaBeans architecture as a way to provide the system services that most enterprise applications need. The EJB architecture frees enterprise application developers from concerns about these services, enabling them to concentrate on providing robust, highly functional business logic.
The Enterprise JavaBeans architecture provides various types of enterprise beans to model business objects: entity beans, stateful and stateless session beans, and message-driven beans. Choose a particular enterprise bean type to model a business concept depending on the application's needs for robust data handling, efficient behavior, and maintaining client state during a user session.
An entity bean provides an object-oriented view of stored data, such as relational data stored in a database; a stateless session bean gives a procedural view of the data. An application component provider should use entity beans to model logical entities such as records in a database. When implementing behavior to visit multiple rows in a database and present a read-only view of data, stateless session beans are the best choice. They are designed to provide generic services to multiple clients.
Some business concepts actually require more than one view of data. An example would be a catalog that provides browsing and searching services as well as mechanisms to update the product information. In such cases, you can use a stateless session bean to operate on product information as a whole and an entity bean to provide access to a particular product.
Enterprise beans implemented as remote objects consume a significant amount of system resources and network bandwidth. Because of this overhead, they are not appropriate for modeling all business objects. Instead, an application component provider can implement certain enterprise beans as local objects, with a remote enterprise bean as a facade to the local beans. Or, you can use data access objects to encapsulate database access and value objects to model objects that are dependent on enterprise beans.
Also, it may not be appropriate to give clients direct access to all enterprise beans used by an application. Some enterprise beans may act as mediators for communication between clients and the EJB tier. Such beans can encapsulate work flow specific to an application or can serve as an entry point to a hierarchy of information.