1 2 Previous Next 16 Replies Latest reply on Feb 29, 2004 9:43 PM by Alexey Loubyansky

    Foreign Key within Composite Primary Key and CMR

    cwolf2 Newbie

      Hi,


      I'm having a problem with CMR and composite primary keys, and however hard I try I just can't get it to work. I'd be grateful if someone could help me, or put me out of my misery by telling me it isn't possible.

      What I'm trying to do is to setup a one-to-many foreign key mapping where the foreign key is part of a composite primary key - in my case between tables:

      ord (primary key = orderid) and

      ordline (primary key = orderid, orderlinenumber)

      where ordline.orderid is a foreign key to table ord.

      When I try to deploy (under both 3.2.1 and 3.2.2RC4) I get a duplicate column name error as JBOSS tries to create ordline.orderid twice.

      If you have got this working could you let me see the relevant sections of your jbosscmp-jdbc.xml and ejb-jar.xml files, or let me know changes necessary to my deployment files (relevant sections of which are shown below).


      Thanks,
      Chris.

      P.S. I can easily e-mail all the source files upon request.


      ejb-jar.xml (abridged):
      -----------------------

      <ejb-jar>
      <enterprise-beans>


      <ejb-name>Order</ejb-name>

      <cmp-field>
      <field-name>orderID</field-name>
      </cmp-field>

      <cmp-field>
      <field-name>customerName</field-name>
      </cmp-field>

      <cmp-field>
      <field-name>orderDate</field-name>
      </cmp-field>

      <primkey-field>orderID</primkey-field>




      <ejb-name>OrderLine</ejb-name>
      <prim-key-class>chrisw.order.OrderLinePK</prim-key-class>

      <cmp-field>
      <field-name>orderLinePK</field-name>
      </cmp-field>

      <cmp-field>
      <field-name>quantity</field-name>
      </cmp-field>

      <primkey-field>orderLinePK</primkey-field>


      </enterprise-beans>




      <ejb-relation>
      <ejb-relation-name>Order-OrderLine</ejb-relation-name>

      <ejb-relationship-role>
      <ejb-relationship-role-name>order-orderlines</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Order</ejb-name>
      </relationship-role-source>

      <cmr-field>
      <cmr-field-name>orderLines</cmr-field-name>
      <cmr-field-type>java.util.Set</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>orderline-order</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>OrderLine</ejb-name>
      </relationship-role-source>

      <cmr-field>
      <cmr-field-name>order</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>



      </ejb-jar>



      jbosscmp-jdbc.xml (abridged):
      -----------------------------

      <jbosscmp-jdbc>

      <enterprise-beans>


      <ejb-name>Order</ejb-name>
      <table-name>ord</table-name>

      <cmp-field>
      <field-name>orderID</field-name>
      <column-name>orderid</column-name>
      </cmp-field>

      <cmp-field>
      <field-name>customerName</field-name>
      <column-name>customername</column-name>
      </cmp-field>

      <cmp-field>
      <field-name>orderDate</field-name>
      <column-name>orderdate</column-name>
      </cmp-field>



      <ejb-name>OrderLine</ejb-name>
      <table-name>ordline</table-name>

      <cmp-field>
      <field-name>orderLinePK</field-name>

      <property-name>orderID</property-name>
      <column-name>orderid</column-name>


      <property-name>orderLineNumber</property-name>
      <column-name>orderlinenumber</column-name>

      </cmp-field>

      <cmp-field>
      <field-name>quantity</field-name>
      <column-name>quantity</column-name>
      </cmp-field>



      </enterprise-beans>



      <ejb-relation>
      <ejb-relation-name>Order-OrderLine</ejb-relation-name>
      <foreign-key-mapping/>

      <ejb-relationship-role>
      <ejb-relationship-role-name>order-orderlines</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>orderID</field-name>
      <column-name>orderid</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>orderline-order</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      </ejb-relation>



      <dependent-value-classes>
      <dependent-value-class>
      Order Line multi-part primary key
      chrisw.order.OrderLinePK

      <property-name>orderID</property-name>
      <column-name>orderid</column-name>


      <property-name>orderLineNumber</property-name>
      <column-name>orderlinenumber</column-name>

      </dependent-value-class>
      </dependent-value-classes>

      </jbosscmp-jdbc>

        1 2 Previous Next