title: Mapping property in EmbeddedId to Many to many relationship
body: <p>I have 3 entities User, Organization ,Permission. A user can have access to multiple organization but role(single) and permissions (multiple) will be different. Now  for mapping these in jpa i have created User, Organization ,Permission and UserOrganization with  EmbeddedId UserOrganizationId (for managing multiple org for single user). now i want to map single record  for user org to permission but could figure out how to achieve this.</p>
  <p>Here are my entities (Setter , getters and other function are omitted)</p>
  <pre><code>@Entity
  @Setter
  @Getter
  public class User {
      @Id
      @GeneratedValue(generator = &quot;uuid2&quot;)
      @GenericGenerator(name = &quot;uuid2&quot;, strategy = &quot;uuid2&quot;)
      @Column(columnDefinition = &quot;UUID&quot;,updatable = false, nullable = false)
      private UUID id;
      private String email;   
      @OneToMany(mappedBy = &quot;orgnaization&quot;)
      private Set&lt;UserOrganization&gt; userOrgnaizations =  new HashSet&lt;&gt;();;
  }
  
  
  
  @Entity
  @Setter
  @Getter
  public class Organization {
      @Id
      @GeneratedValue(generator = &quot;uuid2&quot;)
      @GenericGenerator(name = &quot;uuid2&quot;, strategy = &quot;uuid2&quot;)
      @Column(columnDefinition = &quot;UUID&quot;,updatable = false, nullable = false)
      private UUID  id;  
      private String name;
      @OneToMany(mappedBy = &quot;user&quot;)
      private Set&lt;UserOrganization&gt; userOrgnaizations = new HashSet&lt;&gt;();
      
      public void addUser(User user , Role role , Set&lt;Permission&gt; permissions) {
          UserOrganization userOrganization = new UserOrganization();
          userOrganization.setUser(user);
          userOrganization.setOrgnaization(this);
          userOrganization.setRole(role);
          userOrganization.setPermissions(permissions);       
          userOrgnaizations.add(userOrganization);        
          user.getUserOrgnaizations().add(userOrganization);
      }
  }
  
  @Entity
  @Setter
  @Getter
  public class UserOrganization {
  
      @EmbeddedId
      private UserOrganizationId userOrganizationId;
  
      @Column
      private Role role;
  
      @ManyToOne
      @MapsId(&quot;orgnaizationId&quot;)
      @JoinColumn(name = &quot;orgnaization_id&quot;, columnDefinition = &quot;UUID&quot;)
      private Organization orgnaization;
  
      @ManyToOne
      @MapsId(&quot;userId&quot;)
      @JoinColumn(name = &quot;user_id&quot;,columnDefinition = &quot;UUID&quot;)
      private User user;
      
      @ManyToMany(fetch = FetchType.EAGER) 
      @JoinTable( name = &quot;user_orgnaization_permissions&quot;, 
                  joinColumns = @JoinColumn(name = &quot;userOrganizationId.id&quot;, referencedColumnName = &quot;id&quot;),
                  inverseJoinColumns = @JoinColumn(name = &quot;permission_id&quot;, referencedColumnName = &quot;userOrganizationId.id&quot;) 
               )
      private Set&lt;Permission&gt; permissions;
  }
  
  @Embeddable
  @Setter
  @Getter
  public class UserOrganizationId implements Serializable  {
          
      @GeneratedValue(generator = &quot;uuid2&quot;)
      @GenericGenerator(name = &quot;uuid2&quot;, strategy = &quot;uuid2&quot;)
      @Column(columnDefinition = &quot;UUID&quot;,updatable = false, nullable = false)
      private UUID id;
      
      @Column(name = &quot;user_id&quot;)
      private UUID userId;
      
      @Column(name = &quot;orgnaization_id&quot;)
      private UUID orgnaizationId;
      
      @Override
      public boolean equals(Object o) {
          if (this == o) return true;
   
          if (o == null || getClass() != o.getClass())
              return false;
   
          UserOrganizationId that = (UserOrganizationId) o;
          return Objects.equals(orgnaizationId, that.orgnaizationId) &amp;&amp;
                 Objects.equals(userId, that.userId);
      }
   
      @Override
      public int hashCode() {
          return Objects.hash(orgnaizationId, userId);
      }
      
  }
  
  
  @Entity
  @Setter
  @Getter
  public class Permission
  {
      @Id
      @GeneratedValue(generator = &quot;uuid2&quot;)
      @GenericGenerator(name = &quot;uuid2&quot;, strategy = &quot;uuid2&quot;)
      @Column(columnDefinition = &quot;UUID&quot;,updatable = false, nullable = false)
      private UUID id;
      
      private String name;
  }
  </code></pre>
  <p>As stated in code i have tried to mapped ony id to permission but it gives me error if i skip this and only provide @ManyToMany(fetch = FetchType.EAGER)  then it crated an separate table user_orgnaization_permissions with user_organization_id, user_organization_orgnaization_id,user_organization_user_id ,permissions_id but i only want to map user_organization_id to permission id</p>