0 Replies Latest reply on Oct 3, 2007 11:06 AM by marcusdidiusfalco

    JPA question OneToMany, Cascading

    marcusdidiusfalco

      Hallo,

      I want to use an entity which references a collection of other entities like

      @Entity
      public class Fencer implements Serializable {
      
       @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
       @JoinColumn(name="fencer_id")
       public List<Tournament> getTournaments() {
       return tournaments;
       }
      


      When I detach the fencer entity and change it in a remote client so that an entry from the list is removed and then merge it back with
      entityManager.merge(fencer), the entity has the correct state, the deleted entry is gone. But on the DB level the deleted entry in the tournament table still exits. Only the foreign key is set to null.
      This behavior is quite unexpected to me. If I do not remove the orphaned entries, the db will fill up with unneeded entries in the detail tables.
      How do you implement this correctly to avoid this behavior?

      Thanks,

      Hans