This question is very similar to: JPA mapping (Hibernate, EclipseLink): why does this code not work (a chain of two relationships using JPA 2.0, @EmbeddedId composite PK-FK)?
In fact, my only (from the significant that I noticed) difference is what I use @IdClassand that I most likely will not be able to switch to a provider other than sleep mode.
but in any case, this is the code (deleted parts that are not important):
PermissionContextType.java:
@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;
}
}
PermissionContext.java:
@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;
}
}
Permission.java:
@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;
}
}
and I get:
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
- , , ( , ), -
hibernate EAP 6.1 (4.2.0), wildfly ( , ).