-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Is it possible to have enums with my own values handled ?
PostPosted: Thu May 19, 2011 1:03 am 
Newbie

Joined: Thu May 19, 2011 12:59 am
Posts: 13
I know if I have an enum like this:

Code:
public enum MyEnum {
  Y ("Y"), N ("N");

  String value;

  MyEnum (String value) {
    this.value = value;
  }
}


It works fine when I annotate a field with @Enumerated(UserType.STRING)

The "Y" or "N" gets automatically saved/loaded to database

But what if I wanted it to be like:

Code:
public enum MyEnum {
  YES ("Y"), NO ("N");

  String value;

  MyEnum (String value) {
    this.value = value;
  }
}


This no longer works, because when it's trying to save to database for example if I use MyEnum.YES It actually is trying to save "YES" not the value of "Y"

Any way to work around this?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.