-->
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: HB JPA storing Enum on varchar using ordinal values
PostPosted: Tue Mar 17, 2009 8:16 am 
Newbie

Joined: Tue Oct 11, 2005 8:13 am
Posts: 4
Suppose I have this enum:
Code:
public enum Status { OK, NOK, NOT_APPLICABLE }

And this property:
Code:
@Column(name = "status")
@Enumerated(EnumType.ORDINAL)
private Status status;

And this table (legacy, CANNOT be changed):
Code:
CREATE TABLE tb_xxx (
  id bigint NOT NULL,
  status character varying(1) NOT NULL,
)

It leads to this exception:
Code:
java.lang.IllegalArgumentException: No enum const class mypkg.Status.1
   java.lang.Enum.valueOf(Enum.java:196)
   org.hibernate.type.EnumType.nullSafeGet(EnumType.java:110)

Taking a look at EnumType.java, it is clear that Hibernate imposes ordinal stored as number and name stored as varchar.

Is there any way to map enumeration ordinal as varchar?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 17, 2009 8:24 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Hi,
you can use your own UserType. Please look at http://www.hibernate.org/272.html



Please rate if you are satisfied


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 17, 2009 9:44 am 
Newbie

Joined: Tue Oct 11, 2005 8:13 am
Posts: 4
SIau_Tie wrote:
Hi,
you can use your own UserType. Please look at http://www.hibernate.org/272.html


I saw this tip before, but it does not explain how (and if) I can do it "JPA-way"...

Isn't there a standard-compliant solution? It is a requisite of this project: it must not be coupled to a JPA vendor. It works as expected with Toplink...


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.