title: JPA 2 Hibernate mapping with composite key in primary key using @IdClass with 3 tier structure
body: <p>This question is very similar to: <a href="https://stackoverflow.com/questions/4288531/jpa-hibernate-eclipselink-mapping-why-doesnt-this-code-work-chain-of-2-rel">JPA (Hibernate, EclipseLink) mapping: why doesn&#39;t this code work (chain of 2 relationships using JPA 2.0, @EmbeddedId composite PK-FK)?</a> </p>
  
  <p>Actually my only (from meaningful that I spotted) difference is that I use <code>@IdClass</code> and that I most probably won't be able to switch to a different provider than hibernate.</p>
  
  <p>but anyway here is the code (removed parts that where unimportant):</p>
  
  <p><code>PermissionContextType.java</code>:</p>
  
  <pre><code>@Entity
  @IdClass(PermissionContextTypePk.class)
  public class PermissionContextType{
     @Id    
     private String id;    
  
     @Id
     @JoinColumn (name = "PROJECT", referencedColumnName = "ID")
     @ManyToOne ()
     private Project project;
  
     public static class PermissionContextTypePk implements Serializable{
         public String project;
         public String id;
         // ... eq and hashCode here ...
     }
  
  }
  </code></pre>
  
  <p><code>PermissionContext.java</code>:</p>
  
  <pre><code>@Entity
  @IdClass(PermissionContextPk.class)
  public class PermissionContext{
     @Id
     private String id;
  
     @Id
     @JoinColumns ({
              @JoinColumn (name = "PROJECT", referencedColumnName = "PROJECT"),
              @JoinColumn (name = "PERMISSIONCONTEXTTYPE", referencedColumnName = "ID")
          })
     @ManyToOne
     private PermissionContextType permissionContextType;
  
     public static class PermissionContextPk implements Serializable{
        public String id;
        public PermissionContextTypePk permissionContextType;
        // ... eq and hashCode here ...
     }
  }
  </code></pre>
  
  <p><code>Permission.java</code>:</p>
  
  <pre><code>@Entity
  @IdClass(PermissionPk.class)
  public class Permission{
  
     @Id
     private String id;
  
     @Id
     @JoinColumns ({
              @JoinColumn (name = "PROJECT", referencedColumnName = "PROJECT"),
              @JoinColumn (name = "PERMISSIONCONTEXTTYPE", referencedColumnName = "PERMISSIONCONTEXTTYPE"),
              @JoinColumn (name = "PERMISSIONCONTEXT", referencedColumnName = "ID")
          })
     @ManyToOne
     private PermissionContext permissionContext;
  
     public static class PermissionPk implements Serializable{
        public String id;        
        public PermissionContextPk permissionContext;
        // ... eq and hashCode here ...
     }
  }
  </code></pre>
  
  <p>and what I get is: </p>
  
  <pre><code> org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: PermissionContext 
      Caused by: org.hibernate.AssertionFailure: org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: PermissionContext
  </code></pre>
  
  <p>does anybody know if this is a hibernate bug and I should post it on their issue tracking system (and pray that I would be able to update to given hibernate version) or is there something fundamentally wrong with my way of binding the entities?</p>
  
  <p>I've checked it with the hibernate implementation on EAP 6.1 (4.2.0) as well as on wildfly (don't really know which one.)</p>