Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
Bean-Managed Persistence and Container-Managed Persistence A Comparison
Implementing BMP is the responsibility of the bean provider. The container provider provides the database persistence functionality for entity beans in CMP. The bean provider has to define the SQL queries for only the finder methods and business methods of the entity bean. Tools provided by the container provider aid the bean provider in implementing the actual database functionality for container-managed persistence in entity beans, thus making CMP a lot simpler and easier to use. On the other hand, in BMP the bean provider has a lot more tasks to perform, such as writing the SQL queries as well as the JDBC code in the entity bean to access the database. This makes using BMP for entity beans a much more complex and time-consuming activity. Because the database access code is written by the bean provider, BMP allows developers more flexibility in implementing and performing database persistence. Essentially, if any complex data needs to be packaged in the entity bean, BMP is more useful than CMP. Because the entire database accessing functionality is generated by the container provider's tools, an extra layer of abstraction is added. This makes it difficult to modify or enhance entity beans that use CMP. A drawback of embedding JDBC code in the entity bean using BMP is that the implementation gets tied to a specific database. This is because the different aspects of the database, like database column types and so on, are directly referred to in the embedded JDBC code. An entity bean that uses CMP, however, does not contain any database-specific code. The database-specific code is generated by the CMP tools of the container provider. Hence, porting the entity bean from one database to another, or even one EJB container provider to another EJB container provider, is easier. Now you can try a hands-on example of an entity bean that uses BMP. |