-->
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.  [ 3 posts ] 
Author Message
 Post subject: Java 5 enum & CHAR(1) column
PostPosted: Sat Oct 28, 2006 5:13 am 
Newbie

Joined: Sat Oct 28, 2006 4:59 am
Posts: 1
Does anybody know, how to handle Java 5 enum type with Hibernate Annotations to save the value as CHAR(1)?

For example:

@Entity
class Contract {

public enum State { DRAFT, VALID }

private State state;

...

@Enumerated(EnumType.String)
public String getState() {
return state;
}

...

}

I need to save DRAFT as 'D' and VALID as 'V' into CHAR(1) column.

Thans a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 3:11 pm 
Newbie

Joined: Thu Dec 02, 2004 2:13 pm
Posts: 10
I'm looking for something like this as well, aside from making the enum name the char(1) value you wish to have stored in the db I don't see how this can be done since it appears that Enum.name() is what is providing the string to put in the db.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 11:12 pm 
Newbie

Joined: Mon Jul 10, 2006 5:52 pm
Posts: 6
Location: Bay Area, California, USA
You can use a char member variable in your java class & map it with access=field. Lazy initialization of the enum variable can be done from the char variable, and setting the enum variable can set the char as well.

I was faced with a similar situation where I want to use the wonderful java 5 enums and I ended up having an int type shadow variable holding the ordinal value and I use this in the mapping documents.

Best Wishes
Ram


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

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.