-->
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.  [ 5 posts ] 
Author Message
 Post subject: count(1) in HQL resulting in Error
PostPosted: Mon Aug 21, 2006 2:53 pm 
Beginner
Beginner

Joined: Tue Aug 08, 2006 11:53 am
Posts: 37
Hi,

The following HQL is resulting in parsing error at count (1). The problem is at the numeric 1 I am using in the count function. If i use a column name instead of the constant, the query executes successfully. Is this a restriction of hibermate?

select count(1) from Csa c where c.equipment.equipmentType = 'MA'

Thanks for your help!

Hibernate version: 3.x


Top
 Profile  
 
 Post subject: Re: count(1) in HQL resulting in Error
PostPosted: Mon Aug 21, 2006 3:01 pm 
Newbie

Joined: Mon Aug 21, 2006 2:39 pm
Posts: 2
triveni wrote:
Hi,

The following HQL is resulting in parsing error at count (1). The problem is at the numeric 1 I am using in the count function. If i use a column name instead of the constant, the query executes successfully. Is this a restriction of hibermate?

select count(1) from Csa c where c.equipment.equipmentType = 'MA'

Thanks for your help!

Hibernate version: 3.x


¿Why are you using a constant instance of the column name? you must use a column name within the count function. the use is exactly the same as SQL COUNT Sintaxys


Top
 Profile  
 
 Post subject: better performance
PostPosted: Mon Aug 21, 2006 3:05 pm 
Beginner
Beginner

Joined: Tue Aug 08, 2006 11:53 am
Posts: 37
COUNT(1) gives get better performance as the database engine will not have to fetch back the data fields if column name is used


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 23, 2006 12:18 am 
Newbie

Joined: Thu Jul 27, 2006 11:36 am
Posts: 10
If you are concerned about performance and not fetching everything while doing a count you can try the following:

You can count the number of query results without actually returning them:
Code:
( (Integer) session.iterate("select count(*) from ....").next() ).intValue()


This tip is from here:
http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html


Top
 Profile  
 
 Post subject: JTA spec!
PostPosted: Wed Aug 23, 2006 12:55 pm 
Beginner
Beginner

Joined: Tue Aug 08, 2006 11:53 am
Posts: 37
Thanks for the tip,

However i am planning to stick with the count(id) paradigm as using iterate or scroll in the JTA environment forces us to explicily close them due to some hole in the JTA spec!


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