File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes CMP and BMP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "CMP and BMP " Watch "CMP and BMP " New topic


Rajesh Pathak
Ranch Hand

Joined: Aug 15, 2002
Posts: 56
When we are using CMP Entity Bean, all data access logic is taken care of by the container.
Now my question is, what are various situations when we are bound/recommended to use BMP.

Thanks in advance.

Rajesh(Bangalore,India)<br />SCJP2, SCWCD, SCEA, IBM-XML, UML-OOAD, IBM-Enterprise Connectivity with J2EE.
Ashoke Bhowmick

Joined: Sep 10, 2002
Posts: 13
I don't think there is a compulsion or binding to use BMP in any scenerio.
But following are the advantages of BMP over CMP.
1. It is easier to debug.
2. It gives tremendous flexibility on how you want to map your objects to the database.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
I agree. If you take CMP out of the picture then Entity Beans offer zero benefit over plain Java classes or JDO wrapped with Session Beans.
Christine King

Joined: Aug 26, 2002
Posts: 4
One of my favorite comprehensive J2EE references is "Professional Java Server Programming, J2EE 1.3 Edition" by Allamaraju et al. (WROX). Their recommendation for CMP v. BMP is to stick with CMP unless you really need BMP:
"...The basic problem is that, although every EJB 2.0-compliant container must provide support for container-managed persistence, the specification does not indicate *how* this support must be provided. In fact, a container need not necessarily provide any CMP support for mapping your entity bean's state to columns in a database. It could use Java serialization to write the whole bean to one column and still be compliant. This would rarely be adequate for a project, and might necessitate the use of bean-managed persistence if your EJB container used serialization.
"On the other hand, this extreme case doesn't exist in real life. Every single application server with EJB support of which I am aware, including the open source ones, has some support for mapping your objects to the fields in a relational database.
"The trick is determining whether your EJB container has the level of support for container-managed persistence that you require. If it does, take advantage of this support to free your business-logic programmers from writing persistence logic. The boost in productivity is potentially very large, and depending on the EJB container, the boost in application performance may be large, too."
It goes on to say that you will probably need to use BMP is your target data store is an ERP system or some other existing application.

Malay Thakkar
Ranch Hand

Joined: Jun 22, 2000
Posts: 52
Hi Rajesh,
The difference is that CMP beans rely on the container for the persistence of a bean's data and is hence easier to develop, whereas BMP beans rely on the bean to persist its own data.
But to decide on when to go for BMP is more of a design decision that weighs on performance, flexibility, database independence, application server independence, maintainability, and convenience.
1. Many times Performance is one of the only bottle neck so if your beans can be deployed in any application server, and you know what you are doing with JDBC and EJB (a very big concern!), BMP should always win out over CMP in performance.
2. Bean-managed beans also offer greater flexibility with respect to the type of data they are representing.Sometimes, the nature of your database schema does not mix well with the object-oriented representation that you are trying to develop, leaving you with no choice other than to use BMP.
3. BMP beans, to some degree, are more application server-independent; they are more dependent on the database schema. Once the database schema is in place, however, BMP beans are easier to move around to different application servers.
4. Bean-managed beans have their downside too: maintainability and convenience. BMP beans are tied very closely to a database schema (the code to access specific tables and column names is hard-coded in the bean itself.) CMP beans can be configured at deployment time; a bean can be mapped to a specific table and its fields to that table's columns. A change in the database schema does not necessarily equate to a change in the bean; a smart object-mapping tool can hide some of the changes, but a major overhaul will affect the bean code, regardless.
I agree. Here's the link:
subject: CMP and BMP
It's not a secret anymore!