Topics

Introduction To top of page

This guideline focuses on designing entity beans. Additional guidance on entity beans, such as how to identify and model them, is provided by Guidelines: Entity Beans. General guidance on EJBs is provided by Guidelines: Enterprise JavaBeans (EJBs).

Persistent Attributes and Primary Key To top of page

Identify the persistent attributes and the primary key of the entity bean.

Bean-managed Persistence (BMP) vs. Container-managed Persistence (CMP)To top of page

See Concepts: J2EE Platform Overview for a description of these two approaches to persistency.

In general, container-managed persistence requires less and simpler code than bean-managed persistence. However, if performance is critical or more control over the logical to database mapping is required, then you might need to use bean-managed persistence.

If your EJB container doesn't have the level of support that you require, you may wish to consider using a third-party, object-relational mapping tool, either with bean-managed persistence or, if the tool is integrated with your container, with container-managed persistence.

If you decide to use container-managed persistence and there is a a Data Model, you can map the CMP entity EJB's to database tables in the Data Model. This mapping will ultimately be reflected in the deployment descriptor of the EJB modules. For more information, see Guidelines: Assembling J2EE Modules.

If you decide to use bean-managed persistence, encapsulate all database access within a Data Access Object (DAO) class. This is just a Java class that hides and encapsulates the underlying storage mechanism, and isolates changes when, and if, the interface to the data source changes. Even if the data source is expected to always be an RDBMS, there could be subtle differences in SQL syntax and format that will benefit from being isolated in a DAO class. See Core J2EE Patterns - Data Access Object Pattern ([ALU01].



Rational Unified Process   2003.06.15