Using JPA, can we define an enum as id of an entity?
I've tried the following:
public enum AssetType {
....
}
@Entity
@IdClass(AssetType.class)
public class Adkeys {
private AssetType type;
@Id
@Enumerated(EnumType.STRING)
@Column(nullable = false)
public AssetType getType() {
return type;
}
}
Using OpenJPA, it complains:
org.apache.openjpa.persistence.ArgumentException: The id class "class aa.AssetType" specified by type "class aa.Adkeys" does not have a public no-args constructor.
So my questions are:
- should we able to use enum as id for an entity on JPA? (i.e. there is a bug in OpenJPA)
- or do I make a mistake somewhere?
- and is there any workaround for such problem?