-->
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.  [ 6 posts ] 
Author Message
 Post subject: Simple select with count .. howto ?
PostPosted: Tue Jun 01, 2010 2:51 am 
Newbie

Joined: Fri May 21, 2010 8:37 am
Posts: 14
Got a simple select (ex):
Code:
Select book.name as Bookname,
          author.name as Authorname,
          Count( Distinct(book.publisher) ) as Numberofdiffrentpublisher
From book, author
Where book.author_id = author.author_id,
         book.publishdate <= {somedate},
         book.publishdate >= {somedate}



How do I accomplish this in Hibernate ?


Top
 Profile  
 
 Post subject: Re: Simple select with count .. howto ?
PostPosted: Tue Jun 01, 2010 4:44 am 
Newbie

Joined: Fri May 21, 2010 8:37 am
Posts: 14
Made the follwing criteria, but the result set is empty.
Code:
DetachedCriteria query = DetachedCriteria.forClass(Book.class)
.add(Restrictions.between("publishDate", startDate, endDate))
.setProjection(Projections.countDistinct("publisher"));
List retVal = hibernateTemplate.findByCriteria(query);


Can't seem to wrap my head around what's wrong. Anyone able to help ?


Top
 Profile  
 
 Post subject: Re: Simple select with count .. howto ?
PostPosted: Tue Jun 01, 2010 6:13 am 
Newbie

Joined: Fri May 21, 2010 8:37 am
Posts: 14
Doh - forgot to define the annoted class in the hibernate config *smackshead*

Anyhow - Another problem now:

the countdistinct didn't act as I had expected. I thought it would run as "Count ( Distinct( "properety") )" but when I check the select generated, it only use "Count( "property" ).

Does Countdistinct only count the number of rows ? i thought the rowCount was for that (?)

Anyone ?


Top
 Profile  
 
 Post subject: Re: Simple select with count .. howto ?
PostPosted: Wed Jun 02, 2010 2:36 am 
Newbie

Joined: Fri May 21, 2010 8:37 am
Posts: 14
So, after abit more search I've discovered it -IS- broken -> http://opensource.atlassian.com/project ... e/HHH-4957


Top
 Profile  
 
 Post subject: Re: Simple select with count .. howto ?
PostPosted: Wed Jun 02, 2010 5:41 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
the issues says "fixed in 3.5.2", you might want to update.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Simple select with count .. howto ?
PostPosted: Wed Jun 02, 2010 6:17 am 
Newbie

Joined: Fri May 21, 2010 8:37 am
Posts: 14
Aye - did so :)

and now it works :)


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