| Suppose we have the following:
public class CompositeKey implements Serializable {
private Long id1;
private Long id2;
public CompositeKey(Long id1, Long id2) {
super();
this.id1 = id1;
this.id2 = id2;
}
...
}
public class InheritedKey extends CompositeKey {
private Long id3;
public InheritedKey(Long id1, Long id2, Long id3) {
super(id1, id2);
this.id3 = id3;
}
...
}
@Entity(name = "IKE")
@IdClass(InheritedKey.class)
public class InheritedKeyEntity {
@Id
private Long id1;
@Id
private Long id2;
@Id
private Long id3;
private String name;
...
}
Currently, Hibernate does not include InheritedKey#id3 in InheritedKeyEntity's composite key unless InheritedKey is annotated with @MappedSuperclass. A class used as an IdClass does not need any annotations (as opposed to a class used for an EmbeddedId class, which requires @Embeddable). Since the class used as an IdClass does not need to be annotated, it seems kind of strange that its superclass would need to be annotated with @MappedSuperclass in order for its fields/properties to be persistent. Since the field/property names must match what is annotated in an IdClass, it is clear that the field/property in a superclass is intended to be included in the ID. The fix for this issue would make annotating the superclass of a class used as an IdClass with @MappedSuperclass optional. |