2 Replies Latest reply on May 23, 2006 3:11 PM by jrinderle

    cascade delete fails for 1-to-1 relationship in CMP bean (JB

    jrinderle Newbie

      I am experiencing a problem with cascade delete for CMP beans under JBoss 3.2.x. I have run into this scenario in a few places now (in distinct applications) and I do not know if I am doing something wrong of if this behavior is a bug.

      I have three entity beans: A, B, and C. A relates to 0 or 1 of B (one-to-one) and 0 to n of C (one-to-many). I have specified cascade delete for both relationships such that if A is removed the related B and C entities should be removed as well.

      Setting org.jboss.ejb.plugins.cmp to DEBUG, I see the following behavior. When A is removed, the delete cascades as expected to C. The container then deletes B without first nulling the foreign key in A, resulting in an error. There is no update query to null the b_guid column.

      Within bean A:

       /**
       * @ejb.interface-method
       *
       * @ejb.relation
       * name="A-B"
       * role-name="A-has-0-to-1-B"
       * cascade-delete="no"
       *
       * @jboss.relation
       * fk-column="b_guid"
       * fk-constraint="yes"
       * related-pk-field="guid"
       */
       public abstract _BLocal getBLocal();
      
       /**
       * @ejb.interface-method
       */
       public abstract void setBLocal(_BLocal bLocal);
      
       /**
       * @ejb.interface-method
       *
       * @ejb.relation
       * name="A-C"
       * role-name="A-has-1-to-n-C"
       * cascade-delete="no"
       */
       public abstract Collection getCLocal();
      
       public abstract void setCLocal(Collection cLocal);
      


      Within bean B:
       /**
       * @ejb.interface-method
       *
       * @ejb.relation
       * name="A-B"
       * role-name="A-has-1-B"
       * cascade-delete="yes"
       *
       * @jboss.relation
       * fk-column="a_guid"
       * fk-constraint="yes"
       * related-pk-field="guid"
       */
       public abstract _ALocal getALocal();
      
       public abstract void setALocal(_ALocal aLocal);
      


      Within bean C:
       /**
       * @ejb.interface-method
       *
       * @ejb.relation
       * name="A-C"
       * role-name="A-has-1-C"
       * cascade-delete="yes"
       *
       * @jboss.relation
       * fk-column="a_guid"
       * fk-constraint="yes"
       * related-pk-field="guid"
       * batch-cascade-delete="yes"
       */
       public abstract _ALocal getALocal();
      
       /**
       * @ejb.interface-method
       */
       public abstract void setALocal(_ALocal aLocal);
      


      The names of the beans have been changed to protected the innocent, but I have this exact same situtation (i.e. pattern of bean relationships) in two applications I am working on currently. In both cases the cascade delete fails.

      Any idea what I am doing wrong? Thanks!