when comparing CMP and BMP which one is better for
(a) Database vendor independence (b) application server independence.
quite a few mock test carried the answer as CMP is better for both (a) and (b)
Isn't that not so true. Have you tried to use a CMP code generated by websphere for instance to run in Weblogic. Its not plug and play definitely.
Alternatively if ansi-sql is used in bmp, then bmp is more portable for both (a) and (b)
what are your thoughts ?
You're partially right in say that BMP could be more portable than CMP, since in order to use the CMP features of an specific application server, there are many descriptors (XML) vendor specific.
If you really use only Ansi-SQL, you could achieve the same portability offered by CMP model.
But, there are anothers reasons to say that CMP is much more better that BMP, for example:
- CMP offers CMR's for CMP fields: This feature offers much more integrity for the application, and provides performance by the use of local interfaces (EJB 2.0) - Because the Entity beans are controlled by the container, it can take the control about the resources used to maintain the persistence, like: Sinchronization, Connection Factories, Etc. Many programmers do not carry about this issues, creating potentials scalability bottlenecks. - The EJB container can ensure the system scalability using CMT transactions. Since Entity beans MUST use CMT model, the container can control how the transactions are used over the application. A very common mistake done by many programmers, is make an inapropriated use of UserTransaction interface (JTA).
Transactions must be focused, and more shortest as possible. I have seen many programmers starting transactions, and create ilogical conditions to terminate them, using commits or rollbacks the take a very long time to occur. This bad management of transactions, is the primary factor to decrease the application scalability (because to much resources are being used) and the application performance (At EJB 2.0, do not exist any nested transaction feature, so, the container must use the FIFO strategy to demand aplication requests).
When an architect decided to use CMP, he should think primarily in this points, and for last, worry about the database | application server independence. The reason for this is, there are too many ways to achieve this independence, such as:
- Use the Data Access Object Pattern - Use O-R Mappings Frameworks like JDO, Hibernate, Toplink, iBatis
And do not forget one of the most importante architectural non functional requirements: The application code must be easy to maintain (Maintainability). So, you the programmer hard code SQL at the code, the maintainence to fix some code problem or implement new features (anyway, every kind of potencial change request), will be very hard.