Friday, February 9, 2007

Container-Managed vs Bean-Managed Persistence

1. speed. You can avoid some of the unnecessary container initialized databases calls, if you use BMP's
2. In CMP, the developer uses the deployment descriptor to tell the container which attributes of the entity bean to persist.

Bean-Managed persistence gives the developer explicit control of the management of a bean instance's state.

The main advantage of BMP is Database Acess Flexbility ,

LOng back i read that BMP has acts as an interface to complex legacy SQL databases via JDBC and also enterprise data sources such as CICS, MQ-Series e.t.c.,

Disadvantage of BMP is writing the hard program for all callback
methods by us ..

3. For example with BMP, it takes two SQL stements to load an entity bean. the first call- a finder method ( loading only the primary key ) and a second, during ejbLoad() to load the actual data. A collection of n BMP requires n+1 database calls to load that data.(one finder to find a collection of primary keys, and then n loads).

With CMP, the container can reduce the n+1 database calls to a single call, by performing one giant SELECT statement. You set this up using container specific flags."

You can refer "Matering Enterprise Java Beans" second edition Ed Roman.

The container cannot do the same sort of sql optimization for BMPs for the simple reason that the
container has no control over the sqls. One of the main disadvanteges of CMP is that you can'tcall Stored Procedure from CMP.

will go for BMP in the following cases:

1.My persistent data is in non-RDBMS and the EJB container does not
support this.
2.The database schema does not map exactly to Entity fields.
3.For better performance I would like to use Stored procedure.
4.I want to manage relationship between entities for which I need to
use BMP (This is solved by using EJB 2.0 but for preEJB 2.0...)
5.I have my data from different tables or databases.


SOURCE : www.referjava.com

No comments: