Creating Container-managed Entity Beans with JBoss : Page 5

Entity JavaBeans that use container-managed persistence (CMP) are convenient, because they require so little custom code to achieve automatic persistence. But that convenience carries a price: beans using CMP are also ferociously complex to configure, and often difficult to debug. In this article, you will see how to create, configure, and deploy entity beans that use CMP and JBoss.

by Thornton Rose

Oct 24, 2003

Page 5 of 6

The JBoss CMP Descriptor File
The JBoss CMP descriptor file, jbosscmp-jdbc.xml, contains database and relationship mapping information for the entity beans in an EJB jar. For each entity defined in the EJB jar descriptor, the JBoss CMP descriptor must contain one <entity> child element in the <enterprise-beans> element. The <entity> element contains:

<ejb-name> (required). Entity bean name, which must match an <ejb-name> element in the EJB jar descriptor.

<datasource>. JNDI name of data source where entity bean is persisted. This element is required unless specified in the <defaults> element. (See the JBoss documentation for more information.)

<create-table>. Indicator that the table should be created when the entity bean is deployed.

<remove-table>. Indicator that the table should be removed when the entity bean is undeployed.

<pk-constraint>. Indicator that a primary key constraint should be added to the table when it is created.

<read-only>. Indicator that the table cannot be updated.

<read-time-out>. Amount of time (milliseconds) that a read on a read-only field is valid.

<row-locking>. Indicator that row locking should be used in transactions.

<read-ahead>. Indicator that read-ahead caching should be used for queries.

<list-cache-max>. Number of read lists that can be tracked by the entity.

For each container managed field in the entity bean, the <entity> element must contain one <cmp-field>, which includes:

<field-name> (required). Container managed field name. The value should match the <field-name> of a <cmp-field> in the corresponding <entity> in the EJB jar descriptor.

<column-name>. Name of the column that corresponds to the field in the table. The default is the value of <field-name>.

- Indicator that null is not an allowed value. The default for primary key fields and fields with primitive data types is "true".

<jdbc-type>. JDBC type of the field. This element is required only when you include an <sql-type> element. Valid values are the types defined in java.sql.Types. The data source mapping determines the default value.

<sql-type>. SQL type of the table column. This element is required only when <jdbc-type> is specified. Valid values are the types defined by the database. The data source mapping determines the default value.

JBlog's JBoss CMP descriptor contains two <entity> elements, one for Author and one for Story.