2 Replies Latest reply on Dec 11, 2002 7:15 PM by Pete McKinstry

    CMR many-to-one unidirectional relationship

    Pete McKinstry Newbie

      I've got a ReportRequest entity bean & a ReportFormat entity bean that I'd like to associate via a CMR. It should be a many to one relationship that is only navigatable from the request to the format.

      Data Model like so:
      report_request
      --------------
      request_id (PK)
      format_id (FK)

      report_format
      --------------
      format_id (PK)
      description

      However, I'm having a heck of a time getting the deployment descriptor right. Does anyone have an example of how this should look? It gives me the following error when I deploy the jar file:
      org.jboss.deployment.DeploymentException: Role: Report-has-a-Format with multiplicity many using foreign-key mapping is not allowed to have key-fields, ObjectName: jboss.j2ee:jndiName=ejb/ReportRequestRemote,service=EJB

      I do have a key-fields section for the many side of the relationship, but that seems right to me since that's the side I want to navigate from. Not sure if i'm thinking about this wrong or not....

      Anyhow, I've pasted the .xml files below. If anyone has any tips or examples (of many to one), I'd appreciate the help.

      -pgm

      ejb-jar.xml:
      <?xml version="1.0"?>
      <!DOCTYPE ejb-jar PUBLIC
      '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN'
      'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
      <ejb-jar>
      <enterprise-beans>

      <display-name>ReportRequest Entity Bean</display-name>
      <ejb-name>ReportRequest</ejb-name>

      <!-- remote should only be used for testing. -->
      com.rhi.reports.beans.ReportRequestHomeRemote
      com.rhi.reports.beans.ReportRequestRemote
      <!-- all production access should be through local interfaces -->
      <local-home>com.rhi.reports.beans.ReportRequestHomeLocal</local-home>
      com.rhi.reports.beans.ReportRequestLocal
      <ejb-class>com.rhi.reports.beans.ReportRequestBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>ReportRequest</abstract-schema-name>
      <cmp-field><field-name>requestId</field-name></cmp-field>
      <cmp-field><field-name>parameters</field-name></cmp-field>
      <cmp-field><field-name>reportLocation</field-name></cmp-field>
      <cmp-field><field-name>targetSystemId</field-name></cmp-field>
      <cmp-field><field-name>reportId</field-name></cmp-field>
      <cmp-field><field-name>userId</field-name></cmp-field>
      <cmp-field><field-name>parentRequestId</field-name></cmp-field>
      <cmp-field><field-name>modifiedDate</field-name></cmp-field>
      <cmp-field><field-name>creationDate</field-name></cmp-field>
      <primkey-field>requestId</primkey-field>


      <display-name>ReportFormat Entity Bean</display-name>
      <ejb-name>ReportFormat</ejb-name>
      <!-- remote should only be used for testing. -->
      com.rhi.reports.beans.ReportFormatHomeRemote
      com.rhi.reports.beans.ReportFormatRemote
      <!-- all production access should be through local interfaces -->
      <local-home>com.rhi.reports.beans.ReportFormatHomeLocal</local-home>
      com.rhi.reports.beans.ReportFormatLocal
      <ejb-class>com.rhi.reports.beans.ReportFormatBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>ReportFormat</abstract-schema-name>
      <cmp-field><field-name>formatId</field-name></cmp-field>
      <cmp-field><field-name>description</field-name></cmp-field>
      <primkey-field>formatId</primkey-field>

      <query-method>
      <method-name>findByDescription</method-name>
      <method-params>
      <method-param>
      java.lang.String
      </method-param>
      </method-params>
      </query-method>
      <ejb-ql><![CDATA[
      SELECT OBJECT(f)
      FROM ReportFormat f
      WHERE f.description = ?1
      ]]>
      </ejb-ql>


      </enterprise-beans>

      <ejb-relation>
      <ejb-relation-name>
      Report-Format
      </ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>
      Report-has-a-Format
      </ejb-relationship-role-name>

      Many

      <relationship-role-source>
      <ejb-name>
      ReportRequest
      </ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>
      reportFormat
      </cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>
      Format-has-many-Reports
      </ejb-relationship-role-name>

      One

      <relationship-role-source>
      <ejb-name>
      ReportFormat
      </ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>

      ...
      </ejb-jar>


      jboss.xml:
      <?xml version="1.0" encoding="Cp1252"?>

      <enterprise-beans>

      <ejb-name>ReportRequest</ejb-name>
      <jndi-name>ejb/ReportRequestRemote</jndi-name>
      <local-jndi-name>ejb/ReportRequest</local-jndi-name>
      <configuration-name>Standard CMP 2.x EntityBean</configuration-name>


      <ejb-name>ReportFormat</ejb-name>
      <jndi-name>ejb/ReportFormatRemote</jndi-name>
      <local-jndi-name>ejb/ReportFormat</local-jndi-name>
      <configuration-name>Standard CMP 2.x EntityBean</configuration-name>

      </enterprise-beans>


      jbosscmp-jdbc.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC
      "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"
      "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">
      <jbosscmp-jdbc>

      java:/DefaultDS
      <datasource-mapping>Hypersonic SQL</datasource-mapping>
      <create-table>true</create-table>
      <remove-table>true</remove-table>
      <pk-constraint>true</pk-constraint>
      <preferred-relation-mapping>foreign-key</preferred-relation-mapping>

      <enterprise-beans>

      <ejb-name>ReportRequest</ejb-name>
      <table-name>Report_Request</table-name>
      <cmp-field>
      <field-name>requestId</field-name>
      <column-name>request_id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>parameters</field-name>
      <column-name>parameters</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>reportLocation</field-name>
      <column-name>report_location</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>targetSystemId</field-name>
      <column-name>target_system_id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>reportId</field-name>
      <column-name>report_id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>userId</field-name>
      <column-name>user_id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>parentRequestId</field-name>
      <column-name>parent_request_id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>modifiedDate</field-name>
      <column-name>modified_date</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>creationDate</field-name>
      <column-name>creation_date</column-name>
      </cmp-field>


      <ejb-name>ReportFormat</ejb-name>
      <table-name>report_format</table-name>
      <cmp-field>
      <field-name>formatId</field-name>
      <column-name>format_id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>description</field-name>
      <column-name>description</column-name>
      </cmp-field>

      </enterprise-beans>

      <ejb-relation>
      <ejb-relation-name>
      Report-Format
      </ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>
      Report-has-a-Format
      </ejb-relationship-role-name>
      <fk-constraint>true</fk-constraint>
      <key-fields>
      <key-field>
      <field-name>formatId</field-name>
      <column-name>format_id</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>
      Format-has-many-Reports
      </ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      </ejb-relation>

      </jbosscmp-jdbc>