I found a forum with this subject. Using enum as id
But I couldn’t sure that I can do it or not. I think my case is a little bit different.
enum Type {
}
class MyEntityId {
String type;
String key;
}
@Entity
@IdClass(MyEntityId.class)
class MyEntity {
@Enumerated(EnumType.String)
@Id
Type type;
@Id
String key;
}
Is this actually legal by the spec?
If it is, can I have no worries for vendor specific behaviors?
Why not read the linked issue ? It quotes the spec (2.1.4) and says NO you cannot have id fields of Enum type; it doesn’t matter that you have some (invalid) IdClass (since the types of an IdClass have to match the types of the class). So it is not part of the JPA spec, so you are left with vendor-specific behaviour.