Question

What I want to do is when I save School object, I also want to save (or update) students in database. If students are updated then Cities are must also updated.

class Student{

  @JoinColumn(....)
  @ManyToOne(cascade = CascadeType.ALL, optional = false, fetch = FetchType.EAGER)
  private School school;

  @JoinColumn(....)
  @ManyToOne(cascade = CascadeType.ALL, optional = false, fetch = FetchType.EAGER)
  private City city;

}


class School{

  @OneToMany(cascade = CascadeType.ALL, mappedBy = "....", fetch=fetchType.LAZY)
  private List<Student> studentList;

}

Pas de solution correcte

Autres conseils

class Student{

  @ManyToOne
  private School school;

  @ManyToOne(cascade = CascadeType.MERGE)
  private City city;

}


class School{

  @OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE})
  private List<Student> studentList;

}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top