I have a parent entity (User) with 2 connected one-to-many entities (Apps, Docs). When I create a new one, everything is fine: the parent entity and connected entities are created (in the database). But when I update these entities (after modifying the data), I get the error "A different object with the identifier value [model.App # 124]" session).
What could be the problem? Could not find relevant information through Google (perhaps, hands are not from there).
Thank you in advance!!!

Code:

Class User @LazyCollection(LazyCollectionOption.FALSE) @OneToMany(cascade = CascadeType.ALL, mappedBy = "user") private List<App> apps; @LazyCollection(LazyCollectionOption.FALSE) @OneToMany(cascade = CascadeType.ALL, mappedBy = "user") private List<Doc> docs; Class App @ManyToOne(optional = false) @JoinColumn(name="user_id",referencedColumnName="id") private User user; Controller Save for(int i=0;i<user.getDocs().size();i++) { user.getDocs().get(i).setUser(user); } for(int i=0;i<user.getApps().size();i++) { for(int j=0;j<user.getApps().get(i).getMarks().size();j++) { user.getApps().get(i).getMarks().get(j).setApp(user.getApps().get(i)); } user.getApps().get(i).setUser(user); user.getApps().get(i).setCreate_date(); } userService.saveUser(user); Update for(int i=0;i<user.getDocs().size();i++) { user.getDocs().get(i).setUser(user); } for(int i=0;i<user.getApps().size();i++) { for(int j=0;j<user.getApps().get(i).getMarks().size();j++) { user.getApps().get(i).getMarks().get(j).setApp(user.getApps().get(i)); } user.getApps().get(i).setUser(user); user.getApps().get(i).setUpdate_date(); } userService.updateUser(user); 
  • Please, ask questions in Russian - Sublihim
  • Corrected, thanks for the tip! - Max Black

0