0 Replies Latest reply on Mar 27, 2008 11:38 AM by Armenio Pinto

    Deleting one side of a ManyToMany

    Armenio Pinto Newbie

      Hi there!

      I have a ManyToMany relation between ClassA and ClassB, defined in the following way:

      ClassABean.java:

      @ManyToMany
      @JoinTable(name="a_b",
       joinColumns=@JoinColumn(name="aid", referencedColumnName="id"),
       inverseJoinColumns=@JoinColumn(name="bid", referencedColumnName="id"))
      public Set<ClassBBean> getMyBs()
      


      ClassBBean.java:
      @ManyToMany(mappedBy="myBs")
      public Set<ClassABean> getMyAs()
      


      The problem is that when I try to delete a ClassB entity, it fails with the violation if an integrity constraint (child record found). If I put a CascadeType.ALL in the ClassB definition, it deletes the corresponding ClassA entity, even if it has other associations... What I want is to just delete de ClassB entity!

      Can anyone help me? What am I missing? Thanks a lot in advance,

      AP