-->
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.  [ 10 posts ] 
Author Message
 Post subject: Unknown ordinal value for enum class
PostPosted: Mon Jan 23, 2006 2:42 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
"Unknown ordinal value for enum class" ??? QUE? Please help.

The value in the DB is 0 for an TINYINT column (MSQL).

Hibernate 3.1rc1
Annotations (latest one)

public enum LevelEnum
{
AN(1),
RE(2);

LevelEnum(int aVal)
{
val = aVal;
}

public int getVal()
{
return(val);
}

private int val;
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 23, 2006 6:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If your posting (or a question you are referring to) was not answered by anybody, the possible reasons are:

- http://www.hibernate.org/ForumMailingli ... AskForHelp
- You did not submit enough information
- Nobody knows the answer or has the free time to answer

What you can do now:

- Do the things listed in After Posting
- Add missing and/or more information
- Consider commercial support for guaranteed expert response times

This is a high-traffic forum run by volunteers with hundreds of postings made every day. The community works because people try to help others in their free time. Nobody is paid for this service or has to pay.

You should not expect a timely response and you should not rely on a public community forum for critical cases.

All community members should respect the rules of this forum and treat others like they would prefer to be treated.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 12:57 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
Unknown ordinal value for enum class LevelEnum: 257

Persisting to the database gives a value of 0 and 1 for AN and RE resp in the database. However, trying to retrieve the TestBean from the database gives the above "unknown ordinal" value error. If AN, then 256, if RE is 257, but where does the 256 and 257 values come from?

Also, @Enumerated(ORDINAL) and @Enumerated(STRING) does not seem to work...ie...symbol not found.

SQLQuery q = hSession.createSQLQuery("select {tb.*} from TestBean tb where name=:name");
q.setString("name",aName);
q.addEntity("tb",TestBean.class);
return((TestBean)q.uniqueResult());

Annotations: 3.1 beta8
Hibernate: 3.1.1 (prod)
MySQL 4.x
MySQL column: level and INTEGER type.


public enum LevelEnum
{
AN,
RE;
}


class TestBean
@Enumerated
public LevelEnum getLevel()
{
return level;
}

public void setLevel(LevelEnum level)
{
this.level = level; }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 1:00 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
Btw, here is the stack trace...

java.lang.IllegalArgumentException: Unknown ordinal value for enum class LevelEnum: 257
at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:92)
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:1899)
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:569)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:117)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1672)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:147)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:169)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 2:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Does it work if you retrieve if from a HQL query?
For "symbol not found" be sure to properly use the lastest ejb3-persistence.jar

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 1:59 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
It works with HQL...

Query q = hSession.createQuery("from TestBean tb where name=:name");
q.setString("name",aName);
return((TestBean )q.uniqueResult());

but

@Enumerated(STRING) is still "symbol not found" Quite sure I pulled the ejb3-persistence.jar from the 3.1 beta8 annotations .zip.


emmanuel wrote:
Does it work if you retrieve if from a HQL query?
For "symbol not found" be sure to properly use the lastest ejb3-persistence.jar


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 4:42 am 
Newbie

Joined: Tue Jan 03, 2006 7:30 am
Posts: 18
Location: Budapest, Hungary
hiberdude wrote:
@Enumerated(STRING) is still "symbol not found" Quite sure I pulled the ejb3-persistence.jar from the 3.1 beta8 annotations .zip.

Is this the exact code? Did you put
Code:
import static javax.persistence.EnumType.*;
at the beginning? if not, you should rather write
Code:
@Enumerated(EnumType.STRING)


If this doesn't help: exactly which symbol is not found?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 5:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
OK open a JIRA issue with a runnable testcse on the native query failing, I'll need to have a look.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 11:13 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
Arrgh, but of course...yes...I should have know as the code did not look quite "java" without static import....:)

This part is working now after I used EnumType.STRING. Thanks.

tpalfalvi wrote:
hiberdude wrote:
@Enumerated(STRING) is still "symbol not found" Quite sure I pulled the ejb3-persistence.jar from the 3.1 beta8 annotations .zip.

Is this the exact code? Did you put
Code:
import static javax.persistence.EnumType.*;
at the beginning? if not, you should rather write
Code:
@Enumerated(EnumType.STRING)


If this doesn't help: exactly which symbol is not found?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 11:13 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
emmanuel wrote:
OK open a JIRA issue with a runnable testcse on the native query failing, I'll need to have a look.


ANN-235


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.