Skip to Main Content
Java Enterprise Best Practices
book

Java Enterprise Best Practices

by O'Reilly Java Authors
December 2002
Intermediate to advanced content levelIntermediate to advanced
288 pages
9h 46m
English
O'Reilly Media, Inc.
Content preview from Java Enterprise Best Practices

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.

Example 2-10. 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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Moving to Java 9: Better Design and Simpler Code

Moving to Java 9: Better Design and Simpler Code

Trisha Gee
Java EE 8 High Performance

Java EE 8 High Performance

Romain Manni-Bucau

Publisher Resources

ISBN: 0596003846Supplemental ContentErrata Page