Java Reference
In-Depth Information
Chapter 21: Bean-Managed Persistence
In This Chapter
Bean-managed persistence is discussed in detail in this chapter. The entity object persistence model is
explained. and the development of bean managed persistence EJBs are illustrated with examples. After
reading this chapter, you should be able to develop your own EJBs using bean managed persistence.
Entity-Object Persistence
A business entity is a business object representing some information an enterprise maintains. A
business entity has state, represented by the values of its data fields, and this state is kept persistently
in a persistent store, typically in a database. As discussed in Chapter 20 , an entity-bean instance
represents a business-entity object stored in such persistent storage.
The methods of the entity bean class allow the client to access the business-entity object's state
through the bean instance. In other words, the state of an entity object is maintained and persisted
outside the bean instance, in persistent storage. This mechanism is illustrated in Figure 21-1 .
Figure 21-1: Entity object's state maintained in persistent store
Separating the state of the entity-bean objects from the bean instances has the following advantages:
 
Facilitates data persistence. The separation permits the life cycle of the entity object's state to
go beyond the life cycle of the entity-bean instances and even beyond the life cycle of the JVMs in
which the instances are created.
 
Facilitates the transaction. Persistent stores (for example, relational databases), instead of the
EJB container, are responsible for the implementation of transaction behavior to keep the atomicity,
consistency, isolation, and durability (the so-called ACID properties). This takes advantage of the
built-in functionality of a relational database management system and greatly simplifies the
implementation of EJB container.
 
Promotes distributed component model. The separation makes it possible to implement the
entity object's state so that it is accessable concurrently from multiple JVMs running on different
network nodes. This is essential to the implementation of EJB server clusters that provide load
balancing and fail-over for large-scale applications.
 
Improves accessibility of non-Java applications. The separation makes it possible to
externalize an entity object's state in a representation suitable for non-Java applications. For
instance, if a relational database maintains the state of the entity objects, the state is available to
any application that can access the database via SQL statements.
The entity-bean architecture is flexible regarding the choice of the type of the persistent store. It can be
a relational database; a hierarchical database; an object-oriented database; an XML database; an
LDAP server; a file system; an application; and so on. In practice, however, most applications use
relational databases as persistent stores. When the state of an entity object is maintained in a persistent
data store, an entity-bean instance must use an API specific to the persistent store to access the state
of the associated entity object.
As you have learn in Chapter 20 , an entity-bean instance can access the state of its associated entity
object using two access styles: BMP and CMP. The BMP implements the persistence in the EJB class
or in one or more helper classes, whereas the CMP delegates the handling of its persistence to the EJB
container. BMP is discussed in detail in following sections, and CMP is the topic of the next chapter .
Bean-Managed Persistence
Search WWH ::




Custom Search