Currently we have a validation that checks that all fields of an @IdClass are included in the corresponding entity class as @Id annotated properties. We do not, however, check if there are more @Id annotated fields in the entity than what we expect, and this causes unexpected behavior (i.e. the additional @Id field might “override” the @IdClass and be set as simple-valued identifier for the entity class). For example:
public static class PK {
private Long id;
private String username;
}
@Entity
@IdClass( PK.class )
public static class User {
@Id
private Long id;
@Id
private String username;
@Id
private Integer anotherId;
}
This should be considered a wrong mapping, and an appropriate error should be thrown. |