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;

}

No correct solution

OTHER TIPS

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;

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top