[JPA_SPEC-47] Usability of @Enumerated and @MapKeyEnumerated Created: 11/Feb/13  Updated: 28/Apr/15

Status: Open
Project: jpa-spec
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major
Reporter: jd3714att Assignee: ldemichiel
Resolution: Unresolved Votes: 7
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Tags: enum, jpa


In mapping a pre-existing schema, it is rarely possible to map a given set of constants using an @Enumerated:

  • Ordinals are non-sequential
  • Names are incompatible with Java Enum Constants
  • Names cannot be aliased to something more useful or conventional for Java Naming standards

Limitation is because specification states the name() will be used of an enum.
A typical example: Database uses 'N/A', which can never be mapped to an enum. Intuition will let us look for a solution to map this to 'NOT_AVAILABLE', both a valid name for an Enum Constant, and also conventional naming.

On top of this, an enum often has a representation in the Database, and a constant has usually other additional attributes that could be useful.
Better than using the name() of an @Enumerated, we should map the enumerated similar as an @Entity, and use the @ID.

Comment by jd3714att [ 26/Nov/14 ]

Would this not be more elegant than using a @Converter to solve the problem.

public enum Language {
  private String code;
  private String description;

  Language(String code) {
    this.code = code;
  public String getCode() {
    return code;

  public String getDescription() {
    return description;
Comment by HajoLemcke [ 16/Dec/14 ]

This looks great. And it would solve the problem to have a separate converter for each enumeration because a generic converter can not be build type save.

Comment by rbygrave [ 28/Apr/15 ]

I don't think @Column(name="DESCRIPTION") is required. The only requirement is to mark the field (as you have done with @ID) or mark a getter method that returns the value to be stored in the DB.

So instead annotate the getCode() method like:

public String getCode() { return code; }


public String getCode() { return code; }

Another alternative would be to create an annotation that acts just like @XmlEnumValue does for xml mapping ... so create a @DbEnumValue such that:

public enum Language {


Generated at Fri Oct 09 00:09:13 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.