4 Replies Latest reply on Jan 7, 2003 6:54 AM by Alex Shneyderman

    foreign-key mapped relationship problem

    Craig Hamilton Newbie

      I get the following error when I try and deploy a couple ejb's. (jboss 3.2b3)

      Depends On Me: org.jboss.deployment.DeploymentException: Atleast one role of a foreign-key mapped relationship must have key fields: ejb-relation-nam
      =Activity-ActivityDetail, ObjectName: jboss.j2ee:jndiName=ActivityBean,service=EJB
      state: FAILED

      Here is my jbosscmp-jdbc relationship section


      <ejb-relation>
      <ejb-relation-name>Activity-ActivityDetail</ejb-relation-name>

      <foreign-key-mapping/>

      <ejb-relationship-role>
      <ejb-relationship-role-name>activities-have-details</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>recordID</field-name>
      <column-name>activityRecordID</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>details-belong-to-activity</ejb-relationship-role-name>
      <key-fields/>

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


      I have moved the keyfields from role to role, and fiddled with values for the key-fields, but all i ever get is the error stating I need key fields.

      The activity ejb contains details, a 1-N unidirectional relationship.

      Any help would be appreciated.

      thanks,

      craig

        • 1. Re: foreign-key mapped relationship problem
          Alex Shneyderman Newbie

          can you post your Activity bean's descriptor from ejb-jar?

          • 2. Re: foreign-key mapped relationship problem
            Craig Hamilton Newbie


            <![CDATA[This is the Activity entity bean.]]>

            <ejb-name>ActivityBean</ejb-name>

            test.ActivityBeanHome
            test.ActivityRemote
            <local-home>test.ActivityBeanLocalHome</local-home>
            test.ActivityLocal

            <ejb-class>test.ActivityBeanCMP</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>ActivityBean</abstract-schema-name>
            <cmp-field >
            <![CDATA[Returns the ActivityID]]>
            <field-name>activityID</field-name>
            </cmp-field>
            <cmp-field >
            <![CDATA[Returns the Year]]>
            <field-name>year</field-name>
            </cmp-field>
            <cmp-field >
            <![CDATA[Returns the ID]]>
            <field-name>recordID</field-name>
            </cmp-field>
            <cmp-field >
            <![CDATA[Returns the Activity Description]]>
            <field-name>description</field-name>
            </cmp-field>
            <cmp-field >
            <![CDATA[Returns the Work Comments]]>
            <field-name>workComments</field-name>
            </cmp-field>
            <cmp-field >
            <![CDATA[Returns the Accomplishments in terms of number of accomplishments of the specified unit of measure]]>
            <field-name>accomplishments</field-name>
            </cmp-field>
            <cmp-field >
            <![CDATA[Returns the Unit of Measure]]>
            <field-name>unitOfMeasure</field-name>
            </cmp-field>

            <!-- Write a file named ejb-finders-ActivityBean.xml if you want to define extra finders. -->


            <!--
            To add entity beans that you have deployment descriptor info for, add
            a file to your XDoclet merge directory called entity-beans.xml that contains
            the markup for those beans.
            -->

            <!-- Message Driven Beans -->
            <!--
            To add message driven beans that you have deployment descriptor info for, add
            a file to your XDoclet merge directory called message-driven-beans.xml that contains
            the <message-driven></message-driven> markup for those beans.
            -->

            </enterprise-beans>

            <!-- Relationships -->

            <ejb-relation >
            <ejb-relation-name>Activity-ActivityDetail</ejb-relation-name>

            <ejb-relationship-role >
            <ejb-relationship-role-name>activities-have-details</ejb-relationship-role-name>
            One
            <relationship-role-source >
            <ejb-name>ActivityBean</ejb-name>
            </relationship-role-source>
            <cmr-field >
            <cmr-field-name>details</cmr-field-name>
            <cmr-field-type>java.util.Collection</cmr-field-type>
            </cmr-field>
            </ejb-relationship-role>

            <ejb-relationship-role >
            <ejb-relationship-role-name>details-belong-to-activity</ejb-relationship-role-name>
            Many
            <relationship-role-source >
            <ejb-name>ActivityDetailBean</ejb-name>
            </relationship-role-source>
            </ejb-relationship-role>

            </ejb-relation>

            • 3. Re: foreign-key mapped relationship problem
              Alex Shneyderman Newbie

              Ok, can you add

              <primkey-field>activityID</primkey-field>

              after
              <prim-key-class>

              I suspect that will resolve your problem.

              • 4. Re: foreign-key mapped relationship problem
                Alex Shneyderman Newbie

                I was just reading your posts in other threads that seem to be on the same topic. One thing that comes to my attention is why you have

                <prim-key-class>java.lang.Integer</prim-key-class>

                when you have a composite primary key

                (activtyId,
                year)

                My previous guess was obviously incorrect,
                but I think you just have to clean up your
                ejb-jar and everything must work :-)