This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate enum question  RSS feed

A Harry
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry but a bit new to this!

I'm trying to persist an enum type to Oracle using Hibernate - I've followed the procedure as shown here but what I can't get my head around is how use it in my case - rather than store the ordinal position of the string I'd like to store the enum's id value ?

Any ideas how to modify the example to do this?

My enum looks like this -

public enum Status {
DRAFT(0, "Draft"), RUNNING(1, "Running"), FAILED(2, "Failed"), FINALISED(3, "Finalised");

private intid;
private Stringstr;

private Status(int id, String str) { = id;
this.str = str;

public int getID() {

public String toString() {
return this.str;

public static Status valueOf(int id) {
for (Status status : Status.values()) {
if (status.getID() == id) {
return status;
return null;

many thanks in advance for any help!

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!