1 Reply Latest reply on Apr 20, 2004 1:03 PM by Raja

    How to delete CMR child entities??

    davout Newbie

      Can somebody explain with a code example how to delete all the child entities of a CMR one-to-many relationship without deleting the parent?

      For example: a 'Pupil' entity is associated with one or more 'subject' entities. I have a 'Pupil' entity bean, 'Subject' entity bean and a linking 'PupilSubjectLink' entity bean. This last bean has two fields 'PupilID' and 'SubjectID', both set as keys. I have a CMR one-to-many relationship set up from the 'Pupil' entity to the 'PupilSubjectLink' entity - called 'subjectLinks'.

      Here's my code, from a facade session bean ...


      Pupil aPupil = getHome().findByPrimaryKey(...)
      Collection aSubjectLinks = aPupil.getSubjectLinks;
      Iterator anIterator = aSubjectLinks.iterator();
      while (anIterator.hasNext()) {
      PupilSubjectLink aLink = (PupilSubjectLink) anIterator.next();

        • 1. Re: How to delete CMR child entities??
          Raja Master

          Im hoping u want to remove the association and not remove the Subject Entites as such(as they cud be associated to other pupils).
          If thast what you want, you could get the collection
          and empty the collection as