7 Replies Latest reply on Apr 3, 2002 1:45 AM by knorki

    CMP2 jbosscmp foreignkey mapping problem

    haowu

      I'm using beta 2 playing with CMR. I got everything working, but the column name of the foreign key column seems always picking up the default, which is the CMR field name.

      Here's my jbosscmp.xml section on relationships - The CMR field is author and I would like JBoss to pickup the column name as "PERSON". Am I missing something?

      Hints would be appreciated.

      --Hao


      <ejb-relation>
      <ejb-relation-name>Message-User</ejb-relation-name>
      <foreign-key-mapping>
      <ejb-relationship-role>
      <ejb-relationship-role-name>message-belongsto-user</ejb-relationship-role-name>
      <foreign-key-fields>
      <foreign-key-field>
      <field-name>author</field-name>
      <column-name>PERSON</column-name>
      </foreign-key-field>
      </foreign-key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>user-has-message</ejb-relationship-role-name>
      <foreign-key-fields/>
      </ejb-relationship-role>
      </foreign-key-mapping>
      </ejb-relation>

        • 1. Re: CMP2 jbosscmp foreignkey mapping problem
          ups2000

          I have exactly the same problem
          Anyone can help please?

          • 2. Re: CMP2 jbosscmp foreignkey mapping problem
            pazu

            The DTD for jbosscmp-jdbc.xml has changed between beta1 and beta2. Please take a look at the new DTD.

            <foreign-key-mapping> is now an EMPTY element and you use <key-fields> to indicate which fields are used as foreign key. Read the DTD carefully.

            • 3. Re: CMP2 jbosscmp foreignkey mapping problem
              mcauleyt

              Have a look at this for an example, it might help. Validating against the dtd file is always useful!

              Tim

              *************
              <ejb-relation>
              <ejb-relation-name>Member-MemberInterest</ejb-relation-name>
              <foreign-key-mapping/>
              <ejb-relationship-role>
              <ejb-relationship-role-name>Member-has-MemberInterests</ejb-relationship-role-name>
              <key-fields>
              <key-field>
              <field-name>memberPk</field-name>
              <column-name>member_memberpk</column-name>
              </key-field>
              </key-fields>
              </ejb-relationship-role>
              <ejb-relationship-role>
              <ejb-relationship-role-name>MemberInterest-is-composed-of-a-member-reference</ejb-relationship-role-name>
              <key-fields/>
              </ejb-relationship-role>
              </ejb-relation>

              **************
              ejb-jar.xml
              **************
              <ejb-relation>
              <ejb-relation-name>Member-MemberInterest</ejb-relation-name>
              <ejb-relationship-role>
              <ejb-relationship-role-name>Member-has-MemberInterests</ejb-relationship-role-name>
              One
              <relationship-role-source>
              <ejb-name>MemberEJB</ejb-name>
              </relationship-role-source>
              <cmr-field>
              <cmr-field-name>interests</cmr-field-name>
              <cmr-field-type>java.util.Set</cmr-field-type>
              </cmr-field>
              </ejb-relationship-role>
              <ejb-relationship-role>
              <ejb-relationship-role-name>MemberInterest-is-composed-of-a-member-reference</ejb-relationship-role-name>
              Many
              <relationship-role-source>
              <ejb-name>MemberInterestEJB</ejb-name>
              </relationship-role-source>
              <cmr-field>
              <cmr-field-name>member</cmr-field-name>
              </cmr-field>
              </ejb-relationship-role>
              </ejb-relation>

              • 4. Re: CMP2 jbosscmp foreignkey mapping problem
                knorki

                Could you tell me where i can find the DTDs ? I serched jboss.org and on Sourceforge but i did't find anything... :-(

                thanks

                Knorki

                • 5. Re: CMP2 jbosscmp foreignkey mapping problem
                  haowu

                  Excellent demyth! As soon as I moved out ejb-relationship-role of foreign-key-mapping and added key-fields into it, it worked like a charm.

                  Knorki, the DTD is right under your nose. :) If you have beta2, you must have built by yourself. Check under jboss-all/server/src/resources/org/jboss/metadata. It's also available at http://www.jboss.org/j2ee/dtd, but it has the old version (beta instead of beta2).

                  --Hao

                  • 6. Re: CMP2 jbosscmp foreignkey mapping problem
                    haowu

                    Sorry, I didn't use the tag right. Here's what I did -

                    1. Moved ejb-relationship-role out of foreign-key-mapping
                    2. Add key-fields into ejb-relationship-role.
                    3. You can throw away foreign-key-mapping

                    Note in key-field, the field-name refers to the primary key field(s) of the target Bean, whereas the column-name refers to the source Table.

                    --Hao

                    • 7. Re: CMP2 jbosscmp foreignkey mapping problem
                      knorki

                      Hi ... thanks for the link to the dtd. But I think this dtd is not even for the beta its for the alpha. because beta also uses
                      key-fields instead of foreign-key-fields, but it works fine now

                      cu

                      knorki