title: Hibernate Bidirectional Many to Many implementation
body: <p>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</p>
  
  <pre><code>public class Course implements java.io.Serializable 
  {
      private long courseId;
      private String courseName;
      private Set &lt;Student&gt; Stu = new HashSet &lt;Student&gt;();
  }
  
  public class Student implements java.io.Serializable 
  {
  
      private long studentId;
      private String studentName;
      private Set&lt;Course&gt; courses = new HashSet&lt;Course&gt;();
  }
  </code></pre>
  
  <p>But in the database, I want 3 table to be created 
  Student,Course and StudentCourse</p>
  
  <pre><code>              Student-----&gt;StudentCourse&lt;------Course 
              StudentId      StudentId          CourseId     
                              CourseId     
  </code></pre>
  
  <p>What I want is that when I do </p>
  
  <pre><code> Course C1=(Course)session.get(Course.class,CourseId)
  </code></pre>
  
  <p>I get the specified course and by doing</p>
  
  <pre><code>  Set &lt;Student&gt; StudentsEnrolled=C1.getStu();
  </code></pre>
  
  <p>I get all students enrolled in that course</p>
  
  <p>Similary 
      When I do</p>
  
  <pre><code>Student S1=(Student)session.get(Student.class,StudentId)
  </code></pre>
  
  <p>I get the specified student and by doing</p>
  
  <pre><code>Set &lt;Course&gt; CoursesEnrolled=S1.getCourses();
  </code></pre>
  
  <p>I get all courses the specified student has taken</p>