Hi,
I would like to use an Enumerated type for a column in Hibernate, but I would like the value that is persisted in the database to be obtained via the toString() method. However, Hibernate does not appear to use the toString method to determine the string value stored in the database.
for example,
Code:
enum Fruit
{ APPLE("AP"), ORANGE("OO");
private final String str;
private Fruit(String str) {
this.str = str;
}
@Override public String toString() {
return this.str;
}
}
If I have a mapping using the Enumerated annotation
Code:
@Enumerated(EnumType.STRING)
public Fruit getFruit() {
.....
}
What is stored in the database is NOT "AP" and "OO" but "APPLE" and "ORANGE". It seems as if Hibernate is using the name() method instead of the toString() method to persist the data.
How can I solve this?