0 Replies Latest reply on Dec 27, 2007 1:58 PM by Cory Dahlstrom

    Cascade Delete

    Cory Dahlstrom Newbie

      I'm trying to delete a child object in a @OneToMany relationship and the persistence manager is not removing the child from the database.

      The @OneToMany side is mapped as such:
      @OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")

      The child is mapped as such:
      @ManyToOne
      @JoinColumn(name = "PARENT_ID")

      The code I'm using to do this is (em is the EntityManager):
      Query query = em.createQuery( "... " );
      Parent parent = (RawDaar) query.getSingleResult();
      parent.getChildren().remove(0);

      em.persist( parent );

      I noticed the child delete SQL is not generated and when I find the parent back ( after an em.flush() & em.clear() ), the child still exists.

      If I do a em.remove( child ), that works, but I didn't think I needed that.

      Environment:
      EJB3
      JBoss 4.2.0GA

      Thanks much,

      Cory.