Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPA Enumerated annotation and EnumType.STRING

538367Feb 22 2008 — edited Feb 25 2008
Hi,

There have been a few posts about @Enumeration within JPA.

It seems that if you need to persist values other than the ordinal value
of the enumeration that there is no use in @Enumeration as a JPA
annotation.

Say I have a Enumeration called Fruit.

public enum Fruit{

APPLE,
ORANGE;

}

I have a fruit VARCHAR2(1) column on a table and the constraint is that the value is in ('A', 'O') corresponding to the fruits.

Firstly I annotate a field with @Enumerated(EnumType.String)

Naively I looked at the J2SE 1.5 spec and saw I couldn't override the name() method on the enumeration but rather you are told to override toString().

But Toplink Essentials doesn't use toString() to get the string value of the enumeration it uses????

Is this an area which is addressed in JPA 2.0 or have missed the solution that is available in JPA 1.0 / Toplink Essentials.

Peter.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 24 2008
Added on Feb 22 2008
5 comments
6,733 views