Chapter 11. The Entity-Container Contract
Although each of the three entity type components (EJB 2.0 CMP, EJB 1.1 CMP, and BMP) are programmed differently, their relationships to the container system at runtime are very similar. This chapter covers the relationship between EJBs and their containers. It includes discussions of primary keys, callback methods, and the entity bean life cycle. When differences between the bean types are important, they will be noted.
The Primary Key
primary key is an object that uniquely identifies an entity bean. A
primary key can be any serializable type, including
Long, etc.) or custom classes defined by the bean
developer. In the Ship EJB discussed in Chapter 7, Chapter 9, and Chapter 10, we used the
as a primary key. Primary keys can be declared by the bean developer,
or the primary key type can be deferred until deployment. We will
talk about deferred primary keys later.
Because the primary key may be used in remote invocations, it must
adhere to the restrictions imposed by Java RMI-IIOP; that is, it must
be a valid Java RMI-IIOP value type. These restrictions are discussed
in Chapter 5, but for most cases, you just need
to make the primary key serializable. In addition, the primary key
EJB allows two types of primary keys: single-field and compound. Single-field primary keys map to a single persistence field defined in the bean class. The ...