Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.)
  • <datasource-mapping>. Name of data source type mapping. (Default is "Hypersonic SQL".)
  • <table-name> (required). Name of table where entity data is stored.
  • <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.

// Author entity element in JBoss CMP descriptor <entity> <ejb-name>Author</ejb-name> <table-name>author</table-name> <cmp-field> <field-name>username</field-name> <not-null/> </cmp-field> <cmp-field> <field-name>password</field-name> <not-null/> </cmp-field> <cmp-field> <field-name>name</field-name> </cmp-field> </entity> // Listing 10: Story entity element in JBoss CMP descriptor <entity> <ejb-name>Story</ejb-name> <table-name>story</table-name> <cmp-field> <field-name>storyId</field-name> <column-name>story_id</column-name> <not-null/> </cmp-field> <cmp-field> <field-name>pubDate</field-name> <column-name>pub_date</column-name> <not-null/> </cmp-field> <cmp-field> <field-name>title</field-name> <not-null/> </cmp-field> <cmp-field> <field-name>text</field-name> <not-null/> </cmp-field> <cmp-field> <field-name>username</field-name> </cmp-field> </entity>

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date