5 Replies Latest reply on Sep 10, 2006 11:35 AM by Alan Berezin

    deleting entities from a Collection

    Alan Berezin Newbie

      Sorry if this is a bit of a repost. I am trying to figure out the best way to remove enties from a OneToMany collection (either uni or bidirectional).

      I have an entity Foo, that contains a OneToMany Set:
      Set getBars()

      If I add new Bar objects to the set and call em.merge(myFoo), it properly persists the new Bar objects. However, simply removing Bar objects from the set and calling em.merge(myFoo) does not remove the underlying Bar objects from the db. It seems I have to explicitly call em.remove(myBar1), ...

      Is this how thinks are suppose to work? I could see in a ManyToMany that you could not delete the underlying row simply because it is no longer in the Set. However, in a OneToMany, it would seem that the any Bar objects no longer in the set should be deleted.