1 Reply Latest reply on May 13, 2002 8:22 PM by Dain Sundstrom

    CMP2 bug in recursive relations??

    Kasper Nielsen Newbie

      Hi,

      I've got a problem with defining recursive relationships in Jboss3.0 RC2

      I've got a Group-table (GROUP_ID, NAME, PARENT_GROUP_ID, REALM_ID)

      2 functions in my Bean class
      public abstract java.util.Collection getSubGroups();
      public abstract void setSubGroups(java.util.Collection groups);

      and my ejb.jar file:
      <ejb-relation >
      <ejb-relation-name>SecuritG</ejb-relation-name>

      <ejb-relationship-role >
      <ejb-relationship-role-name>one-subgroup-belongs-to-one-group</ejb-relationship-role-name>
      Many
      <relationship-role-source >
      <ejb-name>SecurityGroup</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>

      <ejb-relationship-role >
      <ejb-relationship-role-name>one-group-has-many-subgroups</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>SecurityGroup</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>subGroups</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>

      </ejb-relation>

      and my jboss-cmp file:
      <ejb-relation>
      <ejb-relation-name>SecuritG</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>one-subgroup-belongs-to-one-group</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>one-group-has-many-subgroups</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>groupId</field-name>
      <column-name>PARENT_GROUP_ID</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>

      Somehow Jboss thinks it needs to insert an extra PARENT_GROUP_ID in the sql Insert query!
      I have no trouble with retrieving the subgroup collection, its only when i use any of the create* methods.

      DEBUG [SecurityGroup] Create: pk=304
      DEBUG [SecurityGroup] Executing SQL: SELECT COUNT(*) FROM SECURITY_GROUP WHERE GROUP_ID=?
      00:53:34,998 DEBUG [SecurityGroup] Executing SQL: INSERT INTO SECURITY_GROUP (GROUP_ID, NAME, PARENT_GROUP_ID, REALM_ID, PARENT_GROUP_ID) VALUES (?, ?, ?, ?, ?)
      00:53:34,998 ERROR [SecurityGroup] Could not create entity
      com.sap.dbtech.jdbc.exceptions.DatabaseException: SAP DBTech SQL: [-6001] (at 72) Duplicate column name:PARENT_GROUP_ID

      - Kasper