Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- public class Course {
- // Primary key and other fields would be here...
- @OneToMany(mappedBy = "course", fetch = FetchType.LAZY)
- private List<Student> students;
- // Getters, setters...
- }
- @Entity
- public class Student {
- // Primary key and other fields...
- @ManyToOne(fetch = FetchType.EAGER)
- @JoinColumn(name = "course_id")
- private Course course;
- // Getters and setters...
- }
- Course course;
- // Fetch the course from persistence
- Student student = new Student("John Doe");
- student.setCourse(course);
- course.getStudents().add(student);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement