title: foreign key must have same number of columns as the reference primary key hibernate - many to many
body: <p>I have domain Classes - User, Role, Group, Group Role</p>
  
  <p><strong>User Domain</strong></p>
  
  <pre><code>private long id, 
  private String userName, 
  private String password, 
  Set&lt;Role&gt; roles = new HashSet&lt;Role&gt;();
  </code></pre>
  
  <p><strong>User.hbm.xml</strong></p>
  
  <pre><code>&lt;hibernate-mapping package="uk.co.jmr.sdp.domain"&gt;
  &lt;class name="User" table="user"&gt;
          &lt;id name="id" unsaved-value="-1"&gt;
              &lt;generator class="native"/&gt;
          &lt;/id&gt;
          &lt;property name="userName" column="user_name"/&gt;
          &lt;property name="password" column="password"/&gt;
          &lt;property name="emailId" column="email_id"/&gt;
  
          &lt;set name="roles" table="user_role" lazy="false" cascade="all"&gt;
              &lt;key column="user_id"/&gt;
              &lt;many-to-many column="role_id" class="Role" fetch="join"/&gt;
          &lt;/set&gt;
  
          &lt;set name="groupRoles" table="user_grouprole" lazy="false" cascade="all"&gt;
              &lt;key column="user_id"/&gt;
              &lt;many-to-many column="group_role_id" class="GroupRole" fetch="join"/&gt;
          &lt;/set&gt; 
  
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>I have user_grouprole table as a join table for an User and Set of grouproles
  I have user_role table as a join table for an user and set of roles</p>
  
  <p><strong>Group Domain</strong></p>
  
  <pre><code>private long id;
  private String groupName;
  private Set&lt;Role&gt; roles = new HashSet&lt;Role&gt;();
  </code></pre>
  
  <p><strong>Group.hbm.xml</strong></p>
  
  <pre><code>&lt;hibernate-mapping package="uk.co.jmr.sdp.domain"&gt;
   &lt;class name="Group" table="group"&gt;
   &lt;id name="id" unsaved-value="-1"&gt;
          &lt;generator class="native"/&gt;
   &lt;/id&gt;
   &lt;property name="groupName" column="group_name"&gt;&lt;/property&gt;
  
   &lt;set name="roles" table="group_role" lazy="false" cascade="all"&gt;
          &lt;key column="group_id"/&gt;
          &lt;many-to-many column="role_id" class="Role" fetch="join"/&gt;
      &lt;/set&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p><strong>GroupRole</strong></p>
  
  <pre><code>private long id;
  private Role role;
  private Group group;
  </code></pre>
  
  <p><strong>GroupRole.hbm.xml</strong></p>
  
  <pre><code>&lt;class name="GroupRole" table="group_role"&gt;
      &lt;id name="id" unsaved-value="-1"&gt;
              &lt;generator class="native"/&gt;
      &lt;/id&gt;
      &lt;many-to-one name="role" class="uk.co.jmr.sdp.domain.Role"
              column="role_id" lazy="false" not-null="true" /&gt;
  
      &lt;many-to-one name="group" class="uk.co.jmr.sdp.domain.Group"
              column="group_id" lazy="false" not-null="true" /&gt; 
  
   &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>When I try to test with a main class, I get a mapping error like a hibernate mapping error like
   <strong>Foreign key (FK5110401A8398947:user_grouprole [group_role_id])) must have same number of columns as the referenced primary key (group_role [group_id,role_id])</strong></p>
  
  <p>What is this error? Why I get this error? What should I do to rectify this error??? Any Solutions ?  Can anyone explain what is this error?</p>
  
  <p>Thanks in Advance</p>