Please, explain the deference between CMP & BMP in an entity bean and when to choose one or the other.
Entity beans are basically used to access data from database.
When we use CMP then all the things like opening connection,insertion of data,reterival of data,updation,deletion etc all are managed by container.So you don't have to write code for that but there are overheads on container when we use CMP.
Whereas in BMP you have to write all the code regarding above functions in ur bean class.
I think its beneficial if u use BMP.
I think the real question here is if CMP can be performant enough to use in a real world application. I think the answer is: almost but not yet.
When you have complex entity relationships, use BMP Entity beans. When you have simple relationships, benchmarks CMP performace carefully in your favorite app server container.
I think an even more interesting question is: are Entity Beans evil? Do we really need the overhead of remoting a simple Object wrapper for SQL?
In response to your Evil EJB question. Although SQL is powerful, easy to code, well known and very reliable it has several drawbacks for Enterprise development. They include:
1. Run time only error checking (statement and recordSet field selection).
2. God like power (DELETE FROM table)
3. Proliferation of 'hard coded' strings throughout the code
4. Fixed name dependency turns table/column changes into massive find/replace/compile/test exercises.
5. Portablility between databases is not 100%. I have seen a conversion from Informix to SQLServer take over 8 Months.
6. Detailed and precise A Priori knowlege of the tables and relationships is required to code to SQL.
EJB's solve these problems and encapsulate additional business logic that can be coded once instead of in or after every SQL statement.
We have all seen some pretty 'evil' 2 tier projects that have cost millions to develop and maintain and delivered minimal reuse.
Use bean managed if the container isn't capable of managing the data persistence.
For example if you need to join two tables together, or you need to retrieve data from a legacy system where there is no appropriate jdbc or odbc driver.
I hope this helps.