I am new to hibernate and I want to implement something like this in hibernate. To be able to do this, I am getting problem in setting the xml mapping file. If someone can help me, it would be very nice as this is just of proof of concept I am trying to do, I have much complicated things to do.Thanks
public class Course implements java.io.Serializable
{
private long courseId;
private String courseName;
private Set <Student> Stu = new HashSet <Student>();
}
public class Student implements java.io.Serializable
{
private long studentId;
private String studentName;
private Set<Course> courses = new HashSet<Course>();
}
But in the database, I want 3 table to be created Student,Course and StudentCourse
Student----->StudentCourse<------Course
StudentId StudentId CourseId
CourseId
What I want is that when I do
Course C1=(Course)session.get(Course.class,CourseId)
I get the specified course and by doing
Set <Student> StudentsEnrolled=C1.getStu();
I get all students enrolled in that course
Similary When I do
Student S1=(Student)session.get(Student.class,StudentId)
I get the specified student and by doing
Set <Course> CoursesEnrolled=S1.getCourses();
I get all courses the specified student has taken