-->
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.  [ 6 posts ] 
Author Message
 Post subject: StringValuedEnum broken
PostPosted: Wed Nov 16, 2005 12:14 pm 
Newbie

Joined: Wed Dec 15, 2004 8:32 am
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1rc2/Annotations 3.1beta6

Mapping documents:

public enum AllocationStatus implements StringValuedEnum {
UNALLOCATED("Unallocated"),
ALLOCATED("Allocated"),
SPLIT("Split"),
MERGED("Merged"),
MERGED_AND_SPLIT("Merged/Split"),
REJECTED("Rejected"),
//Values used for displaying in ComboBoxes
ALL("All"),
ALL_PROCESSED("All Processed");

private final String value;

AllocationStatus(final String value) {
this.value = value;
}

public String toString() {
return value;
}

public String getValue() {
return value;
}
}

Code between sessionFactory.openSession() and session.close():
Collection giveUps = query.getExecutableCriteria(session)
.setFetchMode("splits", FetchMode.JOIN)
.setFetchMode("customerAllocations", FetchMode.JOIN)
.setFetchMode("customerAllocations.allocation", FetchMode.JOIN)
.list();

Full stack trace of any exception that occurs:
java.lang.IllegalArgumentException: Unknown name value for enum class com.acme.busobj.enums.AllocationStatus: Rejected
  at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:107)
  at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:104)
  at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
  at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:1898)
  at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1372)
  at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1300)
  at org.hibernate.loader.Loader.getRow(Loader.java:1197)
  at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
  at org.hibernate.loader.Loader.doQuery(Loader.java:689)
  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
  at org.hibernate.loader.Loader.doList(Loader.java:2147)
  at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
  at org.hibernate.loader.Loader.list(Loader.java:2021)
  at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
  at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1483)
  at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
  at com.acme.giveup.PulseGiveUpListener.onMsg(PulseGiveUpListener.java:129)
  at com.tibco.tibrv.TibrvEvent.invoke(TibrvEvent.java:160)
  at com.tibco.tibrv.TibrvImplQueueC.natTimedDispatch(Native Method)
  at com.tibco.tibrv.TibrvImplQueueC.timedDispatch(TibrvImplQueueC.java:48)
  at com.tibco.tibrv.TibrvQueue.timedDispatch(TibrvQueue.java:322)
  at com.acme.rvutil.rvSubjectGroup.run(rvSubjectGroup.java:88)
  at com.acme.rvutil.rvSubjectGroup$QueueDispatcher.run(rvSubjectGroup.java:239
) Caused by: java.lang.IllegalArgumentException: No enum const class com.acme.busobj.enums.AllocationStatus.Rejected
  at java.lang.Enum.valueOf(Enum.java:192)   at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:104)
  ... 22 more

Name and version of the database you are using: Sybase 12

I am using StringValuedEnum as defined in http://www.hibernate.org/273.html. The same code works under hibernate 3.05 with annotations 3.0beta2.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 8:40 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There is no need to implement StringValuedEnum for Hibernate annotations enum types.

It's actually Enum.valueOf() wich fails, wich is pure Java SE 5 API
The name() should be stored not something else.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 9:52 am 
Newbie

Joined: Wed Dec 15, 2004 8:32 am
Posts: 5
I used this approach because I wanted to use names different to the value stored in the database column. Are you saying this is no longer necessary? Have any examples?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 09, 2006 6:44 am 
Newbie

Joined: Wed Dec 15, 2004 8:32 am
Posts: 5
emmanuel wrote:
The name() should be stored not something else.


I still don't have a clue how to fix this. I cannot change my database columns to contain the names of my enums. I've gone down the StringValuedEnum route and now it seems I cannot upgrade to Hib 3.2 because of it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 9:18 am 
Newbie

Joined: Wed Dec 15, 2004 8:32 am
Posts: 5
Can ANYONE suggest how I can fix this? As mentioned before I cannot rename my Enum instances to the values in the database, as this would result in illegal variable names (e.g. "Merged/Split").

Is this functionality not being addressed by Hibernate due to compliance with the EJB spec?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 4:58 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
implement a UserType and mapit with @Type

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.