[JPA_SPEC-47] Usability of @Enumerated and @MapKeyEnumerated Created: 11/Feb/13 Updated: 28/Apr/15
|Remaining Estimate:||Not Specified|
|Time Spent:||Not Specified|
|Original Estimate:||Not Specified|
In mapping a pre-existing schema, it is rarely possible to map a given set of constants using an @Enumerated:
Limitation is because specification states the name() will be used of an enum.
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.
|Comment by jd3714att [ 26/Nov/14 ]|
Would this not be more elegant than using a @Converter to solve the problem.
|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:
Another alternative would be to create an annotation that acts just like @XmlEnumValue does for xml mapping ... so create a @DbEnumValue such that: