Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate enum question

 
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 http://www.hibernate.org/312.html 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) {
this.id = id;
this.str = str;
}

public int getID() {
return this.id;
}

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!

harry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic