Although CMP and BMP entities are programmed differently, their relationships to the container system at runtime is 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 CMP and BMP are important, they will be noted.
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 and Chapter 9, we
Integer type 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
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
equals( ) and
hashCode( ) appropriately.
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 Customer and Ship EJBs, for example, use a
java.lang.Integer primary key ...