Write Dual CMP/BMP Entity Beans
If you are deploying on different platforms, some of which do not support CMP, the usual practice is to write a bean that can support both CMP and BMP, and then set the appropriate implementation in the deployment descriptors. The advantage of this method is that you gain the performance benefits of CMP where it is available, but the application will still work in BMP mode if necessary. Obviously, there is no need to implement BMP if you know CMP will always be available, but on the other hand, it’s not uncommon to write specialized BMP versions to take advantage of particular database features, or even different persistence media.
The dual beans are actually fairly simple to implement. All you have
to do is write a CMP implementation class, and then write a BMP
implementation that overrides accessor methods and
persistence-related methods
(
ejbCreate( )
, ejbRemove( ), etc.).
You don’t have to override ejbActivate( ), ejbPassivate( ),
ejbSetEntityContext( ),
ejbUnsetEntityContext( ), or any business methods
in the CMP class because these do not deal with the persistence
directly.
Example 2-10 shows a pair of CMP and BMP classes.
public class TheCMPBean implements EntityBean { protected EntityContext ctx; public abstract String getName( ); public abstract void setName (String name); public abstract String getAddress( ); public abstract void setAddress (String address); public String ejbCreate (String name, ...