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;
}
How to use cascade.all two-way
문제
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;
}
올바른 솔루션이 없습니다
다른 팁
제휴하지 않습니다 StackOverflow