1 Reply Latest reply on Jul 20, 2004 1:42 AM by Alexey Loubyansky

    many to one bidirectional relationship

    j83 Newbie

      hi, i am converting my cmr from weblogic to JBoss but i having problem when writing data to the database. the foreign key field will always be null when i run the application. i try to map the relation in the ejb-jar.xml and jbosscmp-jdbc.xml. I'm using MySQL as database. but the relation seen not working. Anybody please help and reply to this message

      Thank you...


      ejb-jar.xml
      .....

      <ejb-relation>

      <ejb-relation-name>PageEventBean-WebSessionBean</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>PageEvent-Has-WebSession</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>PageEventBean</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>webSession</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>WebSession-Has-PageEvent</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>WebSessionBean</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>pageEvents</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>
      <ejb-relation>

      <ejb-relation-name>CustomerBean-WebSessionBean</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>WebSession-Has-Customer</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>WebSessionBean</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>customer</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Customer-Has-WebSessions</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>CustomerBean</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>webSessions</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>

      ......



      jbosscmp-jdbc.xml
      .....

      <ejb-relation>
      <ejb-relation-name>PageEventBean-WebSessionBean</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>WebSession-Has-PageEvent</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>webSessionID</field-name>
      <column-name>webSessionID</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>PageEvent-Has-WebSession</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      </ejb-relation>
      <ejb-relation>
      <ejb-relation-name>CustomerBean-WebSessionBean</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>WebSession-Has-Customer</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Customer-Has-WebSessions</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>customerID</field-name>
      <column-name>customerID</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>


      ...

      Any help ?