-->
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.  [ 8 posts ] 
Author Message
 Post subject: Problem resolving property type in where clause
PostPosted: Wed Dec 03, 2003 12:01 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 10:44 am
Posts: 22
I have a column in MySQL which is a smallint unsigned. I am using a short type for this in the hbm.xml file but Hibernate is not liking this in a where clause. What is wrong with this type and how can I track it down?

Thanks,
SZ


net.sf.hibernate.QueryException: could not resolve property type: forumid [select thread.threadid, thread.forumid, thread.title, thread.postusername, thread.replycount, thread.dateline from ForumThread as thread where thread.forumid = 5 order by thread.threadid desc]
at net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:235)
at net.sf.hibernate.hql.PathExpressionParser.end(PathExpressionParser.java:281)
at net.sf.hibernate.hql.WhereParser.doPathExpression(WhereParser.java:366)
at net.sf.hibernate.hql.WhereParser.doToken(WhereParser.java:393)
at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:279)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:120)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:146)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:133)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:352)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:330)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1368)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1332)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1322)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1314)
at PassedThreads.query(PassedThreads.java:28)
at PassedThreads.main(PassedThreads.java:40)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 12:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Is it really forumid, or actually forumId? Show your mapping,


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 12:41 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 10:44 am
Posts: 22
Mapping revealed:

<hibernate-mapping>
<class name="ForumThread" table="thread">
<id name="threadID" type="integer" column="threadid">
<generator class="native"/>
</id>
<property name="title" column="title"/>
<property name="postUserName" column="postusername"/>
<property name="replyCount" column="replycount" type="integer"/>
<property name="dateLine" column="dateline" type="integer"/>
<property name="forumID" column="forumid" type="short"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 1:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
As Gavin was pointing out your property references have Case so you need to use case, eg,

select thread.threadID, thread.forumID, thread.title, thread.postUserName, thread.replyCount, thread.dateLine from ForumThread as thread where thread.forumID = 5 order by thread.threadID desc


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 2:04 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 10:44 am
Posts: 22
Fastest open-source responses I've seen. Thanks.

Since I am using the hibernate2 reference documentation, my contribution back would be to suggest that a paragraph be added in the quickstart section which explains that the query parameters are the class' attribute names and not the table column names. It is easy to miss this with the cat example because there is no difference between the column names and the class attribute names. For somebody racing to get an example up it is easy to miss because the standard SQL paradigm is to use column names. This difference is fundamental and would justify a mention up front.

Still have one more problem, though.

I am getting a class cast exception on the following code:

try {
session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
List threads = session.find(sql);
System.out.println(threads.size() + " thread(s) found");

for (Iterator it = threads.iterator(); it.hasNext();) {
ForumThread thread = (ForumThread) it.next();
System.out.println(thread.getTitle());
}
tx.commit();
} catch (HibernateException e) {
e.printStackTrace();
}

However, this only happens with the full hb-sql (see above) and in spite of the fact that it returns the right number of rows.

If I do something real simple like:

String sql = "from ForumThread";

it works just fine.

Can you clear up this mystery??
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 2:12 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 10:44 am
Posts: 22
Since mapping problems seem like a big stumbling block, it would be nice if there was a debugging level that would print a list of the fields mapped for a persistent class when there is a mapping error. That way a user could immediately see what the fields are and compare with the erroneous query field.

We use this type of debugging for printing event dispatch tables when an event comes in to a dispatcher that doesn't match any of the registered events. It saves a lot of time tracking down errors.

Just an idea.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 8:38 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 10:44 am
Posts: 22
OK, got it. I put the where clause after the 'from ForumThread as thread' clause.

Sorry, it takes a few mistakes to grok that you are really dealing with an OO query language which just resembles SQL.

Here again, it would be great to see some introductory material highlighting the paradigm shift between using SQL and HBSQL.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2003 3:14 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Good suggestion, I'll add it to the documentation.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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