title: org.hibernate.MappingException: collection foreign key mapping has wrong number of columns
body: <p>I have a class <code>Subject</code> as such,</p>
  
  <pre><code>@Entity
  @IdClass(SubjectId.class)
  @Data
  public class Subject {
      @Id
      private String name;
      @ManyToOne
      @JsonBackReference
      @Id
      private Teacher teacher;
      @OneToMany(mappedBy = "student")
      private List&lt;StudentSubject&gt; students;
  }
  </code></pre>
  
  <p>Its composite Id is defined in <code>SubjectId</code> class as such,</p>
  
  <pre><code>public class SubjectId implements Serializable{
      private String name;
      private Teacher teacher;
  
      public SubjectId(String name, Teacher teacher) {
          this.name = name;
          this.teacher = teacher;
      }
      SubjectId(){}
  }
  </code></pre>
  
  <p>On compiling, I get the error </p>
  
  <blockquote>
    <p>org.hibernate.MappingException: collection foreign key mapping has wrong number of columns: com.example.Subject.students type: component[name,teacher]</p>
  </blockquote>
  
  <p>While this points the error to students element, the error occured after I removed the autogenerated id of Subject, and replaced it with combination of name and teacher.</p>
  
  <p>Anyway, <code>students</code> element is mapped in <code>StudentSubject</code> class as such,</p>
  
  <pre><code>@Entity
  @IdClass(StudentSubjectId.class)
  public @Data
  class StudentSubject {
  
      String studentId;
      @ManyToOne
      @Id
      private Subject subject;
      @ManyToOne
      @Id
      private Student student;
  </code></pre>