2 Replies Latest reply on Jul 2, 2004 5:56 AM by rajs1

    Relationship mapping in jbosscmp-jdbc.xml

    rajs1

      I have a Table called


      Country (primary key country_code[String]).
      Trading_Centre (primary key trading_centre_code[String] & foreign key country_code[String] NOT NULL)


      I am trying to establish a entity relationship (all tables exist, create table = false).

      TradingCentre-belongs-to-a-Country
      Country-has-many-TradingCenrtes as follows (ejb-jar.xml):
       <relationships>
       <ejb-relation>
       <ejb-relation-name>CountryEJB - TradingCentreEJB</ejb-relation-name>
       <ejb-relationship-role>
       <ejb-relationship-role-name>Country-has-many-TradingCentres</ejb-relationship-role-name>
       <multiplicity>One</multiplicity>
       <relationship-role-source>
       <ejb-name>CountryEJB</ejb-name>
       </relationship-role-source>
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>TradingCentre-belongs-to-a-Country</ejb-relationship-role-name>
       <multiplicity>Many</multiplicity>
       <relationship-role-source>
       <ejb-name>TradingCentreEJB</ejb-name>
       </relationship-role-source>
       <cmr-field>
       <cmr-field-name>localcountry</cmr-field-name>
       </cmr-field>
       </ejb-relationship-role>
       </ejb-relation>
       </relationships>
      


      How will the equivalent tag in jbosscmp-jdbc.xml be built (JBoss v 3.2.5). I need to use the foreign key country_code in table Trading_Centre to be used to map to the LocalCountry entity. In effect its a many-to-one unidirectional relationship.

      All my attempts so far have resulted in error's when deploying this relationship. I have the AdminDevel_323.pdf document (and associated CrimePortal example) but to no avail.

      Your help would be much appreciated.

      Cheers
      -raj

        • 1. Re: Relationship mapping in jbosscmp-jdbc.xml

          I think this is what you need. The only thing you need to fill in is the field name of the primary key field for the country. I marked where that needs to go in the xml below.


           <ejb-relation>
           <ejb-relation-name>CountryEJB - TradingCentreEJB</ejb-relation-name>
          
           <ejb-relationship-role>
           <ejb-relationship-role-name>TradingCentre-belongs-to-a-Country</ejb-relationship-role-name>
           <key-fields/>
          
           </ejb-relationship-role>
           <ejb-relationship-role>
           <ejb-relationship-role-name>Country-has-many-TradingCentres</ejb-relationship-role-name>
           <key-fields>
           <key-field>
           <field-name>XfieldName of primary key for countryX</field-name>
           <column-name>country_code</column-name>
           </key-field>
           </key-fields>
          
           </ejb-relationship-role>
           </ejb-relation>
          


          Hope this helps,
          Mark

          • 2. Re: Relationship mapping in jbosscmp-jdbc.xml
            rajs1

            Much obliged squire, works a treat.

            Cheers
            -raj