• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Hibernate enum question

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic