1 Reply Latest reply on May 13, 2003 12:22 AM by Dmitry Mozheyko

    EntityBean and Relational database problem

    Eric Chow Apprentice

      Hello,

      Would you please to teach me how can I implement the following table relations in EJB(CMP).


      ITEM
      ======================
      itemNo VARCHAR(30)
      itemName VARCHAR(100)
      desc VARCHAR(500)


      BOOK_ITEM
      ======================
      itemNo VARCHAR(30)
      ISBN VARCHAR(50)


      CD_ITEM
      ======================
      itemNo VARCHAR(30)
      ARTIST VARCHAR(100)



      BOOK_ITEM ------ ITEM -------- CD_ITEM

      the ITEM will links to the BOOK_ITEM and CD_ITEM by using the key itemNo.

        • 1. Re: EntityBean and Relational database problem
          Dmitry Mozheyko Novice

          ######################
          ejb-jar-xml
          ######################

          .........



          <ejb-relation>

          <ejb-relation-name>
          item-book-item
          </ejb-relation-name>

          <ejb-relationship-role>

          <ejb-relationship-role-name>
          item-has-book-items
          </ejb-relationship-role-name>
          One
          <relationship-role-source>
          <ejb-name>ItemBean</ejb-name>
          </relationship-role-source>
          <cmr-field>
          <cmr-field-name>itemBookItems</cmr-field-name>
          <cmr-field-type>java.util.Set</cmr-field-type>
          </cmr-field>
          </ejb-relationship-role>
          <ejb-relationship-role>
          <ejb-relationship-role-name>
          book-item-belongs-to-item
          </ejb-relationship-role-name>
          Many
          <cascade-delete/> <!-- if you need -->
          <relationship-role-source>
          <ejb-name>BookItemBean</ejb-name>
          </relationship-role-source>
          <cmr-field>
          <cmr-field-name>itemNo</cmr-field-name>
          </cmr-field>
          </ejb-relationship-role>
          </ejb-relation>

          <ejb-relation>

          <ejb-relation-name>
          item-cd-item
          </ejb-relation-name>

          <ejb-relationship-role>

          <ejb-relationship-role-name>
          item-has-cd-items
          </ejb-relationship-role-name>
          One
          <relationship-role-source>
          <ejb-name>ItemBean</ejb-name>
          </relationship-role-source>
          <cmr-field>
          <cmr-field-name>itemCDItems</cmr-field-name>
          <cmr-field-type>java.util.Set</cmr-field-type>
          </cmr-field>
          </ejb-relationship-role>
          <ejb-relationship-role>
          <ejb-relationship-role-name>
          book-item-belongs-to-item
          </ejb-relationship-role-name>
          Many
          <cascade-delete/> <!-- if you need -->
          <relationship-role-source>
          <ejb-name>CDItemBean</ejb-name>
          </relationship-role-source>
          <cmr-field>
          <cmr-field-name>itemNo</cmr-field-name>
          </cmr-field>
          </ejb-relationship-role>
          </ejb-relation>
          ....
          ######################
          jbosscmp-jdbc-xml
          ######################

          .....

          <ejb-relation>
          <ejb-relation-name>
          item-book-item
          </ejb-relation-name>
          <foreign-key-mapping/>
          <ejb-relationship-role>
          <ejb-relationship-role-name>
          item-has-book-items
          </ejb-relationship-role-name>
          <key-fields>
          <key-field>
          <field-name>
          itemNo
          </field-name>
          <column-name>
          itemNo
          </column-name>
          </key-field>
          </key-fields>
          </ejb-relationship-role>
          <ejb-relationship-role>
          <ejb-relationship-role-name>
          book-item-belongs-to-item
          </ejb-relationship-role-name>
          <key-fields/>
          </ejb-relationship-role>
          </ejb-relation>


          <ejb-relation>
          <ejb-relation-name>
          item-cd-item
          </ejb-relation-name>
          <foreign-key-mapping/>
          <ejb-relationship-role>
          <ejb-relationship-role-name>
          item-has-cd-items
          </ejb-relationship-role-name>
          <key-fields>
          <key-field>
          <field-name>
          itemNo
          </field-name>
          <column-name>
          itemNo
          </column-name>
          </key-field>
          </key-fields>
          </ejb-relationship-role>
          <ejb-relationship-role>
          <ejb-relationship-role-name>
          cd-item-belongs-to-item
          </ejb-relationship-role-name>
          <key-fields/>
          </ejb-relationship-role>
          </ejb-relation>
          ...