Bean-Managed Persistence Concepts

In container-managed persistence (CMP), as you saw yesterday, the EJB container provider supplies tools that help automate the generation of code required for the entity bean to interact with the database. Bean-managed persistence (BMP) is the other technique used to persist the state of entity beans. In BMP the entity bean itself is responsible for maintaining its state, hence the name. The entity bean has all the functionality built into it for connecting to the database, inserting data in the database, retrieving data from the database, updating data in the database, and so on.

The entity bean uses the life-cycle methods invoked by the EJB container at different points in time to interact with the data. For example, when the entity bean is created, the EJB container invokes the ejbCreate() life-cycle method of the entity bean. The desired result of this invocation is the creation of a row of data in the database. To implement the creation of data in the database when the ejbCreate() method is called, the bean provider needs to write the JDBC code that obtains a JDBC connection, creates an SQL statement, and executes the SQL statement, resulting in a row being created in the database. Any SQL exceptions that occur need to be appropriately handled. This technique, in which the bean provider writes the implementation for the entity bean's persistence, is BMP. Similarly, to retrieve or update data, the bean provider supplies the implementation in the form of JDBC code written in each of the different life-cycle methods.

Because the inherent aspects of an entity bean, apart from the database access implementation, are unchanged in both bean-managed and container-managed persistence, the life cycle of an entity bean that uses either BMP or CMP is exactly the same.



Sams Teach Yourself BEA WebLogic Server 7. 0 in 21 Days
Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
ISBN: 0672324334
EAN: 2147483647
Year: 2002
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net