The app's stack: Spring MVC
, Spring DataJPA
, Hibernate
. There are three entities: student
, tutor
, theme
.
Theme:
@Entity
@Table(name = "themes")
public class Theme {
// fields omitted
}
Student:
@Entity
@Table(name = "students")
public class Student {
private Map<Theme, Tutor> tutors;
// other fields omitted
}
Tutor:
@Entity
@Table(name = "tutors")
public class Tutor {
private Map<Theme, Student> students;
// other fields omitted
}
For save student-tutor-theme
relationships i want use this table (PostgreSQL):
CREATE TABLE themes_students_tutors
(
theme_id INTEGER NOT NULL,
student_id INTEGER NOT NULL,
tutor_id INTEGER NOT NULL,
FOREIGN KEY (theme_id) REFERENCES themes (id) ON DELETE CASCADE,
FOREIGN KEY (student_id) REFERENCES students (id) ON DELETE CASCADE,
FOREIGN KEY (tutor_id) REFERENCES tutors (id) ON DELETE CASCADE
)
How i can to annotate tutors
and students
fields in entities, for their content correct persists in this table?