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: Enum Mapping Types do not use toString() to persist data
PostPosted: Tue Sep 29, 2009 7:47 am 
Newbie

Joined: Tue Sep 29, 2009 7:42 am
Posts: 6
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?


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.