CMP Configuration

JBoss reads the CMP configuration for entity beans from the META-INF/jbosscmp-jdbc.xml file. The JOnAS counterpart to this is the <jdbc-mapping> child element of the <entity> element in the META-INF/jonas-ejb-jar.xml file. Example 2-9 and Example 2-10 provide CMP configuration templates for:

Note that the schema loading/dropping configuration is not exactly parallel between these two schemas. Table 2-3 describes the behaviors that can be specified using JOnAS's cleanup tag.

Example 2-9. jbosscmp-jdbc.xml

<jbosscmp-jdbc>
  ...
  <enterprise-beans>
    ...
    <entity>
      <ejb-name>EJB Name</ejb-name>
      ...
      <datasource>JNDI Datasource</datasource>
      <table-name>Database Table</table-name>
      ...
      <!-- Schema loading/dropping configuration -->
      <create-table>boolean</create-table>
      <drop-table>boolean</drop-table>
      <alter-table>boolean</alter-table>
      ...
      <cmp-field>
        <field-name>Java Field</field-name>
        <column-name>Database Column</column-name>
      </cmp-field>
      ...
    </entity>
    ...
  </enterprise-beans>
  ...
  <relationships>
    ...
    <ejb-relation>
      <ejb-relation-name>Relation Name</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
        <ejb-relationship-role-name>Role</ejb-relationship-role-name>
        <key-fields>
          <keyfield>
	    <field-name>Java Field</field-name>
	    <column-name>Foreign Key Column</column-name>
	  </keyfield>
	</key-fields>
      </ejb-relationship-role>
    </ejb-relation>
    ...
  </relationships>
  ...
</jbosscmp-jdbc>

Example 2-10. jonas-ejb-jar.xml

<jonas-ejb-jar>
  ...
  <jonas-entity>
    <ejb-name>EJB Name</ejb-name>
    ...
    <jdbc-mapping>
      <jndi-name>JNDI Datasource</jndi-name>
      <jdbc-table-name>Database Table</jdbc-table-name>
      ...
      <!-- Schema loading/dropping configuration -->
      <cleanup>cleanup value</cleanup>
      ...
      <cmp-field-jdbc-mapping>
        <field-name>Java Field</field-name>
        <jdbc-field-name>Database Column</jdbc-field-name>
      </cmp-field-jdbc-mapping>
      ...
    </jdbc-mapping>
    ...
  </jonas-entity>
  ...
  <jonas-ejb-relation>
    <ejb-relation-name>Relation Name</ejb-relation-name>
    <jonas-ejb-relationship-role>
      <ejb-relationship-role-name>Role</ejb-relationship-role-name>
        <foreign-key-jdbc-mapping>
          <foreign-key-jdbc-name>Foreign Key Column</foreign-key-jdbc-name>
        </foreign-key-jdbc-mapping>
    </jonas-ejb-relationship-role>
  </jonas-ejb-relation>
  ...
</jonas-ejb-jar>

Table 2-3. Cleanup Values

ValueDescription
removedataat bean loading time, the content of the tables storing the bean data is deleted
removeallat bean loading time, the tables storing the bean data are dropped (if they exist) and created
nonedo nothing
createdefault value (if the element is not specified), at bean loading time, the tables for storing the bean data are created if they do not exist