-->
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.  [ 4 posts ] 
Author Message
 Post subject: help : select max(userID)
PostPosted: Thu Jul 05, 2007 12:33 pm 
Newbie

Joined: Thu Jul 05, 2007 12:25 pm
Posts: 2
Hi,

I am new to hibernate. Could somebody please help me?
Thank you very much.

String hql= "select max(userID) from User";
List list = session.createQuery(hql).list();
int maxID = ( (Integer)list.get(0) ).intValue();

Error message:
Exception in thread "main" java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.IdentNode
+-[IDENT] IdentNode: 'userID' {originalText=userID}

at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:140)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:702)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:531)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:645)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
at com.peng.hibernate.testMain.test(testMain.java:57)
at com.peng.hibernate.testMain.main(testMain.java:17)




<hibernate-mapping>
<class name="com.peng.hibernate.User" table="user" catalog="bookstore">
<id name="userId" type="java.lang.Integer">
<column name="userID" />
<generator class="assigned" />
</id>
<property name="name" type="java.lang.String">
<column name="name" length="45" not-null="true" />
</property>
<property name="password" type="java.lang.String">
<column name="password" length="20" not-null="true" />
</property> <set name="userroles" inverse="true">
<key>
<column name="userID" not-null="true" />
</key>
<one-to-many class="com.peng.hibernate.Userrole" />
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 3:42 pm 
Newbie

Joined: Thu Jan 04, 2007 1:36 pm
Posts: 16
You should be using userId instead of userID in your max() function.
According to the hibernate mapping, userID is the column name..but your field name is "userId" which is what you'd have to use when you're using HQL. I believe its just a simple overlook due to the subtle difference...
Hope that fixes your problem!
Code:
select max(userId) from User

- Arun


Top
 Profile  
 
 Post subject: Thanks !
PostPosted: Fri Jul 06, 2007 1:16 pm 
Newbie

Joined: Thu Jul 05, 2007 12:25 pm
Posts: 2
That's my mistake.
Thanks for helping! arun123


Top
 Profile  
 
 Post subject: Re: help : select max(userID)
PostPosted: Thu Jun 10, 2010 10:00 am 
Newbie

Joined: Thu Jun 10, 2010 9:55 am
Posts: 1
Thanks for posting that. You just saved me a HUGE headache. Even three years after you posted it.

Cheers

Steven


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