CMP/JBoss: The Definitive Guide

By Jeremy Boynes

CMP Fields

CMP Fields are the basic unit of information for CMP Entity beans, and this section covers declaration, coding and serialization issues.

Dependent Value Classes

The EJB specification states that the type of a cmp-field must either be a primitive or a Serializable class. Dependent Value Classes provide a mechanism for mapping more complex Java types onto individual database columns avoiding the need to serialize values into the database.

Container Managed Relationships

Container Managed Relationships (CMR) allow a developer to define relationships between entities that are automatically managed by the CMP implementation. This can be used to simply represent the business data model in the Entity layer and allow applications to easily navigate between entities. Further, by defining the relationships in a manner the EJB Container can understand, it can factor them into the requests it makes to the store, potentially reducing the number of operations needed and significantly improving performance.

Mapping CMRs to SQL Databases

This article describes the mechanisms used by JBoss CMP to map Container Managed Relationships (CMR) defined in the EJB tier to relational databases using SQL.

Finder and ejbSelect Methods

Finder and ejbSelect methods provide a mechanism for locating entities in a persistent store without having to write code to access it natively. The methods allow the programmer to execute the queries; the definition of the query and how it is mapped to the store is defined in the deployment descriptor.

EJB Query Language

EJB-QL is a language for writing the queries that CMP must execute for Finder and ejbSelect. It is similar to the SQL language used for relational databases, but just different enough that subtle differences can lead to confusion. EJB-QL is intended to describe queries operating on a collection of Objects and not on the simple table/row/column structure people are typically familiar with. It is similar to SQL, but is closer to the Object-Relational model of SQL-99 than to traditional SQL-92.

Primary Keys

Primary keys define the identity of a CMP Entity Bean, allowing to be found and operated on. Selecting the right primary key is critical for efficient operation of the CMP engine.

Key Generators

JBoss CMP supports the use of key generators to automatically provide values for EJBs that have an Unknown Primary Key. This article describes the configuration of these key generators.

CMP Managed Audit Fields

CMP has the ability to automatically update certain columns in the database when create or update operations are performed. These can be used to implement a basic auditing strategy.

Locking Mechanisms

JBossCMP works in conjunction with the Entity locking mechanisms in JBoss to control access to CMP Entities and avoid potentially inconsistent modifications to data. Unlike BMP, the application code does not need to participate in the locking strategies.

Tuning CMP Performance

Tuning of JBoss CMP is a finicky and error prone process. This article walks you through the ins and outs of the JBoss CMP tuning options.

JBossCMP Mappings to Physical Databases

Not all databases are created equal. Although the JDBC API provides mechanisms that hide the different physical characteristics of different database systems, there are some issues that it does not address which require JBossCMP to be configured for each platform.