title: ManyToManyToMany - Joining three tables with Hibernate annotations
body: <p>At first I thought <a href="https://stackoverflow.com/questions/6509579/hibernate-how-to-join-three-3-tables-in-one-join-table-in-annotation">this solution</a> might solve my problem:</p>
  
  <pre><code>@Entity
  public class User {
  
      @JoinTable(name = "user_permission",
          joinColumns = @JoinColumn(name = "user_id"),
          inverseJoinColumns = @JoinColumn(name = "permission_id"))
      @MapKeyJoinColumn(name = "project_id")
      @ElementCollection
      private Map&lt;Project, Permission&gt; permissions = new HashMap&lt;&gt;();
  
  }
  
  @Entity
  public class Project {
      ...
  }
  
  @Entity
  public class Permission {
      ...
  }
  </code></pre>
  
  <p>But in this implementation there can only be one <code>Permission</code> set per <code>Project</code>. I'd like to accomplish the ability to set multiple permissions for a project such that the following could be true:</p>
  
  <pre><code>| user_id | project_id | permission_id |
  |---------|------------|---------------|
  | 1       | 1          | 1             |
  |---------|------------|---------------|
  | 1       | 1          | 2             |
  |---------|------------|---------------|
  | 1       | 2          | 1             |
  |---------|------------|---------------|
  | 1       | 2          | 2             |
  |---------|------------|---------------|
  | 2       | 1          | 1             |
  |---------|------------|---------------|
  | 2       | 1          | 2             |
  |---------|------------|---------------|
  | 2       | 2          | 1             |
  |---------|------------|---------------|
  | 2       | 2          | 2             |
  </code></pre>