-->
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.  [ 13 posts ] 
Author Message
 Post subject: How to get the number of rows in the result set
PostPosted: Mon Jul 12, 2004 4:54 pm 
Newbie

Joined: Mon Jul 12, 2004 4:36 pm
Posts: 6
Hi
I'm trying to get the number of rows in the result set without actually getting the result set. An example query looks like this:

select count(*) from (select ... from ... where ...);

sql allows this. when I tried to run it in hiberate, I got an net.sf.hibernate.QueryException. Is the syntax wrong or this is not allowed in hql? Any help is greatly appreciated. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 5:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Why do you need that?
isn't
Code:
select count(*) from MyClass
enough?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 5:47 pm 
Newbie

Joined: Mon Jul 12, 2004 4:36 pm
Posts: 6
emmanuel wrote:
Why do you need that?
isn't
Code:
select count(*) from MyClass
enough?


I'm not counting the rows in one table, but the rows returned by a complex query. Here's the actual query I was trying to run:

select count(*) from (select f.forumId, f.forumName, t.topicId, t.topicTitle, p from Forum f, Topic t, Post p, PostText pt where f.forumId = t.forumId and t.topicId = p.topicId and p.postId = pt.postId and p.postId in (select pt1.postId from PostText pt1 where pt1.postText like '%aa%' or pt1.postText like '%bb%'))

Hope this helps clarify my question. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 5:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
select count(f.forumId) from Forum f, Topic t, Post p, PostText pt where f.forumId = t.forumId and t.topicId = p.topicId and p.postId = pt.postId and p.postId in (select pt1.postId from PostText pt1 where pt1.postText like '%aa%' or pt1.postText like '%bb%')

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 5:54 pm 
Newbie

Joined: Mon Jul 12, 2004 4:36 pm
Posts: 6
emmanuel wrote:
Code:
select count(f.forumId) from Forum f, Topic t, Post p, PostText pt where f.forumId = t.forumId and t.topicId = p.topicId and p.postId = pt.postId and p.postId in (select pt1.postId from PostText pt1 where pt1.postText like '%aa%' or pt1.postText like '%bb%')


It didn't work. Thanks much anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 5:57 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
How does it fail?
Does replacing count(f.forumId) by count(*) solve the problem?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 14, 2004 11:07 am 
Newbie

Joined: Mon Jul 12, 2004 4:36 pm
Posts: 6
emmanuel wrote:
How does it fail?
Does replacing count(f.forumId) by count(*) solve the problem?


both failed with an net.sf.hibernate.QueryException. not much explanation is given.

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 9:42 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Sure Hibernate give some information inside the QueryException (message of the exception). Check the log too.

It should work, are you sure that
Code:
select f.forumId from Forum f, Topic t, Post p, PostText pt where f.forumId = t.forumId and t.topicId = p.topicId and p.postId = pt.postId and p.postId in (select pt1.postId from PostText pt1 where pt1.postText like '%aa%' or pt1.postText like '%bb%')

work ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 5:47 pm 
Newbie

Joined: Mon Jul 12, 2004 4:36 pm
Posts: 6
emmanuel wrote:
Sure Hibernate give some information inside the QueryException (message of the exception). Check the log too.

It should work, are you sure that
Code:
select f.forumId from Forum f, Topic t, Post p, PostText pt where f.forumId = t.forumId and t.topicId = p.topicId and p.postId = pt.postId and p.postId in (select pt1.postId from PostText pt1 where pt1.postText like '%aa%' or pt1.postText like '%bb%')

work ?


the above query works, but if you add select count(*) in the front, it doesn't


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 21, 2004 7:40 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Then, I'm pretty sure that
Code:
select count(f.forumId) from Forum f, Topic t, Post p, PostText pt where f.forumId = t.forumId and t.topicId = p.topicId and p.postId = pt.postId and p.postId in (select pt1.postId from PostText pt1 where pt1.postText like '%aa%' or pt1.postText like '%bb%')

works.

if not try

Code:
select count(f) from Forum f, Topic t, Post p, PostText pt where f.forumId = t.forumId and t.topicId = p.topicId and p.postId = pt.postId and p.postId in (select pt1.postId from PostText pt1 where pt1.postText like '%aa%' or pt1.postText like '%bb%')


I'm interested.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 21, 2004 10:29 am 
Newbie

Joined: Mon Jul 12, 2004 4:36 pm
Posts: 6
emmanuel wrote:
Then, I'm pretty sure that
Code:
select count(f.forumId) from Forum f, Topic t, Post p, PostText pt where f.forumId = t.forumId and t.topicId = p.topicId and p.postId = pt.postId and p.postId in (select pt1.postId from PostText pt1 where pt1.postText like '%aa%' or pt1.postText like '%bb%')

works.

if not try

Code:
select count(f) from Forum f, Topic t, Post p, PostText pt where f.forumId = t.forumId and t.topicId = p.topicId and p.postId = pt.postId and p.postId in (select pt1.postId from PostText pt1 where pt1.postText like '%aa%' or pt1.postText like '%bb%')


I'm interested.


tried all. none worked.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 5:40 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Please post a simple working test case to JIRA, I'll check that.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 9:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Emmanuel, we shouldn't clog up JIRA with things like this, which are sure to be due to simple user error. He can post his mappings and stack trace here, and I'm sure we will immediately see the problem.


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