-->
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.  [ 9 posts ] 
Author Message
 Post subject: Problem with COUNT(*) and new parser
PostPosted: Mon Apr 04, 2005 9:02 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Hibernate version: 3.0 final
Name and version of the database you are using: MySQL 4.0.24

I would like to get the number of elements of a certain object.
The following query works fine with the classic query parser. The exception below is thrown with the new query parser.
The documentation says that COUNT(*) is a supported aggregate function in HQL.


Code
Code:
final StringBuffer buffer = new StringBuffer(200)
      .append("SELECT COUNT(*) FROM Order AS order ")
      .append("JOIN order.versions ")
      .append("WHERE order.node = :node ");
final Session session = Li2DHibernateUtil.getSession();
final Query query = session.createQuery(buffer.toString());
query.setString("node", "12345");
final int result = ((Integer) query.uniqueResult()).intValue();


Exception
org.hibernate.QueryException: Unable to find SQL function: COUNT [SELECT COUNT(*) FROM de.company.project.persistence.Order AS order JOIN order.versions WHERE order.node = :node ]


PS: When searching for an alternative way getting the number of query results, I found the following peace of code in the Hibernate 3.0 documentation. Maybe this part should be removed or replace since Session.iterate is deprecated in Hibernate 3.0...?

Code:
( (Integer) session.iterate("select count(*) from ....").next() ).intValue()


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 8:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Try lower case count(*).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 05, 2005 2:50 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
That seems to work fine.
So this is obviously a bug, isn't it?

The documentation says (PDF page 114) that HQL Queries are case-insensitive, except for names of Java classes and properties.

Should I put this issue to JIRA?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 05, 2005 8:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I have a strong preference for lowercase function names (in fact all lowercase). You could record the issue in JIRA but I suspect the documentation will be updated as the solution.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 06, 2005 12:18 am 
Beginner
Beginner

Joined: Mon Dec 15, 2003 5:25 am
Posts: 48
Location: Delhi, India
david wrote:
I have a strong preference for lowercase function names (in fact all lowercase).


Any specific reason for this preference?

_________________
Vinod K. Singh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 06, 2005 3:30 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
david wrote:
I have a strong preference for lowercase function names (in fact all lowercase). You could record the issue in JIRA but I suspect the documentation will be updated as the solution.


OK, i recorded this issue in JIRA (HHH-313) with the note that either the documentation or the code needs to be updated.
By the way, I have a preference for (at least SQL-similar) uppercase function names. :)


Top
 Profile  
 
 Post subject: Let's not break existing code
PostPosted: Mon Apr 18, 2005 2:19 pm 
Newbie

Joined: Tue May 04, 2004 5:03 pm
Posts: 3
I have a preference not to have to go back and update all my DAO classes to use lowercase function names. There is already enough work to do to upgrade to Hibernate 3. Hibernate 2 does not have this limitation. Please update the code to support case-insensitive function names.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 2:22 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
This has been recently updated with the new release 3.0.1.


Top
 Profile  
 
 Post subject: Re: Let's not break existing code
PostPosted: Mon Apr 18, 2005 2:24 pm 
Newbie

Joined: Tue May 04, 2004 5:03 pm
Posts: 3
Thanks for the fix.


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