-->
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: Mapping Ordinal Enum Values to char(1)
PostPosted: Fri Jan 04, 2008 12:21 pm 
Regular
Regular

Joined: Wed Nov 17, 2004 11:49 am
Posts: 65
Location: Pittsburgh
I am having a problem I do not fully understand. I have a legacy database schema that stores ordinal values for enumerations as char(1). I have the following mapping:

Code:
    /** The current status of this case. */
    @Column(name="STATUS", columnDefinition="char(1)")
    private Status status;


This works OK for create, but on read I get the following exception:

Code:

Caused by: java.lang.IllegalArgumentException: No enum const class foo.bar.bam.Case$Status.2
at java.lang.Enum.valueOf(Enum.java:192)
at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:101)
at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:105)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)



Here's what I don't understand, it seems to me if Hibernate can store the value correctly (as an ordinal), it ought to be able to read it correctly. It looks like there is a mismatch in the logic for EnumType.nullSafeGet and EnumType.nullSafeSet

I am looking into authoring a UserType for this scenario, but I wanted to confirm that this is what is required and that I haven't missed something.


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.