2 Replies Latest reply on Mar 6, 2003 5:14 AM by Christofer Dutz

    Controling the column-name used by Foreign Key Mapping

    Christofer Dutz Newbie

      Hi,

      I am having trouble configuring my CMR-entries managing the Foreign Key Mapping. For example I have a relation "Workorder-Assembly" which assigns each Workorder exactly one Assembly and an Assembly can be assigned to several Workorders. As this is a One-To-Many relationship I configured the One part without any foreign-key-fields (as described in several documentation) and the Many part with field-name and column-name. As far as I understood the whole thing, the field-name is the Primary Key field of the related entity and the column-name is the column name used in the current entities database table (since this doesn't have to be used as a entity field). I am adding some examples of my descriptors. Please help me.

        • 1. Re: Controling the column-name used by Foreign Key Mapping
          Jochen Cordes Novice

          Hi Chris !

          The relation section in jbosscmp-jdbc.xml should read like this:
          <ejb-relation>
          <ejb-relation-name>WorkOrder-Assembly</ejb-relation-name>
          <ejb-relationship-role>
          <ejb-relationship-role-name>WorkOrder-has-a-Assembly</ejb-relationship-role-name>
          <foreign-key-fields/>
          </foreign-key-fields>
          </ejb-relationship-role>
          <ejb-relationship-role>
          <ejb-relationship-role-name>Assembly-has-many-WorkOrders</ejb-relationship-role-name>
          <foreign-key-fields>
          <foreign-key-field>
          <field-name>id</field-name>
          <!-- Primary-Key von AssemblyEnt
          -->
          <column-name>wo_assembly_id</column-name>
          <!-- name fo the column in the WorkOrderEnt-Table that stores the key-data
          -->
          </foreign-key-field>
          </foreign-key-fields>
          </ejb-relationship-role>
          </ejb-relation>

          So basically, you have to define the foreign-key in the section of the bean this foreign-key refers to. Then the foreign-key-field will be created in the table of the other participating bean.

          Hope it helps,

          Jochen.

          • 2. Re: Controling the column-name used by Foreign Key Mapping
            Christofer Dutz Newbie

            Thanks for your help, but It seems something else was wrong. Once again I seem to have mixed up hints for older JBoss versions and new ones. I had to add a &lt;foreign-key-mapping/&gt; field and call the other fields &lt;key-fields&gt; and &lt;key-field&gt;.

            But I wouldn't have come very far if you hadn't given me that tip, because I also had to swap the entries ... thanx a lot :)