0 Replies Latest reply on Jun 5, 2003 12:29 PM by pilania

    1-many relationship cascade-delete problem

    pilania

      I have a EJB A which has a uni-directional 1-many relation with EJB B.

      ejb-jar look like this

      <ejb-relation >
      <ejb-relation-name>A-B</ejb-relation-name>

      <ejb-relationship-role >
      <ejb-relationship-role-name>A has Bs</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>A</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>b</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role >
      <ejb-relationship-role-name>Bs are linked to one A</ejb-relationship-role-name>
      Many
      <cascade-delete/>
      <relationship-role-source >
      <ejb-name>B</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>

      </ejb-relation>

      jbosscmp-jdbc looks like this

      <ejb-relation>
      <ejb-relation-name>A-B</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>A has Bs</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>aId</field-name>
      <column-name>A_ID</column-name>
      </key-field>
      </key-fields>

      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Bs are linked to one A</ejb-relationship-role-name>
      <key-fields/>

      </ejb-relationship-role>
      </ejb-relation>

      when i try to do

      ALocal A= AHome.findByPrimaryKey(new APK(aId));

      a.remove();

      It gives exception unable to update B with null.

      I set synch-on-commit to true in standardjboss.xml in server/default/conf and tried again.

      and it gives constraint exception that child records found.

      I tried to do this remove relationships

      ALocal a= AHome.findByPrimaryKey(new APK(aId));

      Collection transactions = a.getBs();
      Iterator iter = transactions.iterator();
      while(iter.hasNext()) {
      iter.next();
      iter.remove();
      }

      it gives illegalStateException becuase relation collection has changed.

      a.remove();

      Any ideas why is it not working...