5 Replies Latest reply on Sep 21, 2006 3:48 PM by Emmanuel Bernard

    How to cause related entities to update when base entity is

    Alex Titov Newbie

      I have two entities:

      public class Employee {
      ...
       @ManyToOne
       public Organization getPlaceOfWork() {
       return placeOfWork;
       }
       public void setPlaceOfWork(Organization placeOfWork) {
       this.placeOfWork = placeOfWork;
       if(placeOfWork!=null){
       placeOfWork.getEmployees().add(this);
       }
       }
      
      }
      
      public class Organization {
      ...
       @OneToMany(fetch=FetchType.EAGER, mappedBy="placeOfWork")
       public Collection<Employee> getEmployees() {
       return employees;
       }
       public void setEmployees(Collection<Employee> employees) {
       this.employees = employees;
       }
      }

      How can I cause Employees to be set their placeOfWork to null when Organization is removed (like database cascade)? And what should I do, if I want to delete Employees when Organization is removed?