0 Replies Latest reply on Jun 28, 2004 2:39 PM by Amar Patel

    CMP 2.0 EJB relationship problem

    Amar Patel Newbie

      The relationship between the User entity and UserType etity is as follows:
      1 User can only have 1 UserType, but 1 UserType can belong to many Users. Furthermore, User maintains a reference to UserType, but UserType does not have a reference to User. So in ejb-jar.xml, we have defined the one-to-many unidirectional relationship between the UserEJB and the UserTypeEJB is as follows:


      <ejb-relation>
      <ejb-relation-name>User-UserType</ejb-relation-name>
      <ejb-relationship-role>
      One
      <relationship-role-source>
      <ejb-name>UserTypeEJB</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>User-has-a-UserType</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>UserEJB</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>userTypeLocal</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role-name>UserType-has-many-Users</ejb-relationship-role-name>
      </ejb-relation>



      I have also added the following to jbosscmp-jdbc.xml:


      <ejb-relation>
      <ejb-relation-name>User-UserType</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>UserType-has-many-Users</ejb-relationship-role-name>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>User-has-a-UserType</ejb-relationship-role-name>
      <fk-constraint>true</fk-constraint>
      <key-fields>
      <key-field>
      <field-name>userTypeLocal</field-name>
      <column-name>user_type_id</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>



      However, when the inserting the above xml fragment into jbosscmp-jdbc.xml, I get an error saying that there is no ejb-relationship-tag-name element. I do not know the reason for this, as I have followed the dtd for jbosscmp-jdbc.xml, and confirmed that the ejb-relationship-role-name tags match in both jbosscmp-jdbc.xml and ejb-jar.xml.

      Another modification I have tried is removing the relationships tag altogether from jbosscmp-jdbc.xml. This allowed me to deploy my beans. I also added the following cmp-field to the 'user' entity in jbosscmp-jdbc.xml:
      <cmp-field>
      <field-name>userTypeLocal</field-name>
      <column-name>UTL</column-name>

      <property-name>type</property-name>
      <column-name>user_type</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(20)</sql-type>

      </cmp-field>
      This xml fragment is in jbosscmp.xml. The result of this is that there is a field called utl in the user_types table in the database. But the value being inserted into this field is not the foreign key integer id of the user_types table, but a serialized version of the UserTypeEJB.

      Please advise on the following issues described above:
      1. no ejb-relationship-role-name defined error.
      2. serialized UserType being stored in RDBMS table users, instead of foreign key integer.

      Thank you.

      Amar
      amar@omalas.com