1

iam able to create, read and delete self reference entities, but update is not working.

when i update i dont see new values, old values are present

@Entity
@Table(name="EMPLOYEE")

    public class Employee {
    
         @ManyToOne(cascade={CascadeType.ALL})
                @JoinColumn(name="manager_id")
                private Employee manager;
    
                @OneToMany(mappedBy="manager", orphanRemoval=true)
                private Set<Employee> subordinates = new HashSet<Employee>();
    
                      ....getters and setters..........
    }


UPDATE:

 public void updateEmployee(EmployeeDTO employeeDTO ) {
      
           Employee emp= findById(employeeDTO.getId());

           if(!emp.getSubordinates().isEmpty()) {
                   Set<Employee> emps=emp.getSubordinates();
                   emps.clear();
                   employeeDTO.getSubordinates().stream()
                   .map(employeeRepository::findOneById)
                   .forEach(emps::add);
           }
            
    }
     
Augusto
  • 28,839
  • 5
  • 58
  • 88
shrvn
  • 73
  • 7
  • 1
    Does this answer your question? [What is the "owning side" in an ORM mapping?](https://stackoverflow.com/questions/2749689/what-is-the-owning-side-in-an-orm-mapping) <- read this. It's important to understand what is the owning side of a bidirectional association. In other words, changes in the field annotated with `mappedBy` are not taken into consideration when persisting data. – Augusto Feb 27 '21 at 19:29

0 Answers0