2 Replies Latest reply on Mar 29, 2004 1:51 PM by franklemke

    one to many relationship and XDoclet

    franklemke

      I wondered what this errormessage would mean:

      "Atleast one role of a foreign-key mapped relationship must have key fields"

      my ejb-jar.xml deploymentdesriptor is:
      <ejb-relation-name>branche-gruppe</ejb-relation-name>

      <ejb-relationship-role >
      <ejb-relationship-role-name>gruppeRelationshipRole</ejb-relationship-role-name>
      Many
      <relationship-role-source >
      <ejb-name>gruppe</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>branche</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role >
      <ejb-relationship-role-name>brancheRelationshipRole</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>branche</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>gruppen</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>

      I have a 1:n Relationship, and I needed to add the following XDoclet to the
      getBranche-Method in Gruppe, because the relatioship is
      Gruppe(n) (field "branche") - Branche(1) (collection gruppen):

      @jboss.relation fk-constraint = "yes"
      related-pk-field = "id" (id of Branche)
      fk-column = "branche"

      this added the key fields in jbosscmp-jdbc.xml:

      <ejb-relation>
      <ejb-relation-name>branche-gruppe</ejb-relation-name>

      <ejb-relationship-role>
      <ejb-relationship-role-name>gruppeRelationshipRole</ejb-relationship-role-name>
      <fk-constraint>yes</fk-constraint>
      <key-fields/>

      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>brancheRelationshipRole</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>branche</column-name>
      </key-field>
      </key-fields>

      </ejb-relationship-role>
      </ejb-relation>