0 Replies Latest reply on Nov 3, 2001 10:37 AM by milesifr

    CMP delete with autoreferencing FK

    milesifr

      I have CMP (CatProdotto, CatprodottoHome, CatProdottoBean) entity bean that corresponds to the following table Cathegory:

      id
      name
      description
      parent_cathegory (that references id)

      I have written the following recursive function:

      private void removeChildren(Long parentId) throws Exception {
      Collection children = ((CatProdottoHome) _entityContext.getEJBHome()).findByCathegory(parentId);
      System.out.print("\nGot " + children.size() + " children of " + parentId);
      Iterator childrenIt = children.iterator();
      while(childrenIt.hasNext()){
      CatProdotto child = (CatProdotto) PortableRemoteObject.
      narrow(childrenIt.next(), CatProdotto.class);
      removeChildren(child.getId());
      child.remove();
      }
      }


      In the database I have the following tree:

      id=7 parent of id=9 parent of id=11 that has no children.
      The function executes wright until it finds id=11, than
      after calling removeChildren(11) (it dos'nt anything, because 11 has no childre) I call child.remove().
      At this point I get the exception:

      Got 0 children of 11
      [Default]
      Removing 11
      [CatProdottoBean] TRANSACTION ROLLBACK EXCEPTION:Load failed; nested exception i
      s:
      java.rmi.NoSuchObjectException: Entity 11 not found; nested exception is
      :
      java.rmi.ServerException: Load failed; nested exception is:
      java.rmi.NoSuchObjectException: Entity 11 not found
      [CatProdottoBean] java.rmi.ServerException: Load failed; nested exception is:
      [CatProdottoBean] java.rmi.NoSuchObjectException: Entity 11 not found
      [CatProdottoBean] java.rmi.NoSuchObjectException: Entity 11 not found
      [CatProdottoBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCLoadEntityCommand

      and os on..............

      It seems that container call ejbLoad after remove().

      Is this true ? Can I avoid it, it was fixed or teher are workarounds ?

      Thank in advance to anyone helping me

      Ciao Francesco