title: How Do I Create Many to Many Hibernate Mapping for Additional Property from the Join Table?
body: <p>I need a many to many hibernate mapping needed 3 joins. I've tried to find out a solution without intermediate entity like <code>LecturerCourse</code>.</p>
  
  <p>I have a many to many relation in my database between my lecturer and course tables. A course can be given by several lecturer while a lecturer can give several courses.</p>
  
  <p>I have courses stored before hand. However, I need to assign courses to lecturer. When I assign courses I also store the capacity of that course. </p>
  
  <p>My database diagram: </p>
  
  <p><img src="https://i.stack.imgur.com/cE76O.jpg" alt="enter image description here"></p>
  
  <p>I use hibernate and spring. I need a hibernate mapping when a course is assign any lecturer. I need to add values to capacity field.</p>
  
  <p>My lecturer mapping :</p>
  
  <pre><code>@Entity
  @Table(name="LECTURER")
  public class Lecturer {
  
      @Id 
      @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="LECTURER_ID_SEQ")
      @SequenceGenerator(name="LECTURER_ID_SEQ", sequenceName="LECTURER_ID_SEQ")
      private Long Id;
  
      @Column(name="NAME")
      private String name;
  
      @Column(name="SURNAME")
      private String surname;
  
  
      @Column(name="EMAIL")
      private String email;
  
      @Column(name="USERNAME")
      private String username;
  
      @Column(name="PASSWORD")
      private String Password;
  
      @ManyToMany
      @JoinTable(
            name="LECTURER_COURSE",
            joinColumns=@JoinColumn(name="LECTURER_ID"),
            inverseJoinColumns=@JoinColumn(name="COURSE_ID")
        )
      private List&lt;Course&gt; courses;
  
      //getters - setters
  }
  </code></pre>
  
  <p>My course mapping :</p>
  
  <pre><code>@Entity
  @Table(name="COURSE")
  public class Course {
  
      @Id 
      @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="COURSE_ID_SEQ")
      @SequenceGenerator(name="COURSE_ID_SEQ", sequenceName="COURSE_ID_SEQ")
      private Long id;
  
      @Column(name="NAME")
      private String name;
  
      @Column(name="CODE")
      private String code;
  }
  </code></pre>
  
  <p>Any idea how to solve my problem ?</p>