Chapter 5. EJB CMP

Blessed are the sleepy ones: for they shall soon doze off.

Friedrich Nietzsche, Also Sprach Zarathustra

Container-managed persistence (CMP) is a persistence model in which the EJB container worries about persistence issues while you worry about business logic management. Under the CMP model, you leave most of the EJB persistence methods— ejbFindXXX( ), ejbLoad( ), ejbStore( ), and ejbRemove( )—empty. Based on a mapping you define in the application’s deployment descriptor, the container implements those methods and crafts the SQL to map your beans to the database.

EJB 2.0 CMP is a drastic departure from—and improvement upon—EJB 1.0 CMP. Nevertheless, the majority of systems in production these days are still in EJB 1.x environments. This chapter takes a look at both CMP models and describes how to use them in a production environment. As with any automated persistence mechanism, there is not a lot that EJB CMP requires you as the developer to do. The focus for this chapter is specifically on the aspects of the EJB 1.0 and EJB 2.0 CMP models that most impact persistence issues. Once you understand these concepts, you will find that you are left with almost no persistence coding to do under EJB CMP—all your work lies in setting up the database and writing deployment descriptors.

This chapter assumes you have a basic understanding of Enterprise JavaBeans. It specifically assumes that you know the difference between entity and session beans and are familiar with ...

Get Java Database Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.