-->
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.  [ 4 posts ] 
Author Message
 Post subject: Named query help - Count and Group By
PostPosted: Wed Jun 28, 2006 12:01 pm 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
I have two entity types Email and Person. Email Stores the the ID of the Person who has been emailed.

Im having trouble figuring out how to write a named query for nHibernate that returns a list of the top 5 people who have recieved the most emails.

The sql for it would be something like this:

SELECT TOP 5 COUNT(*) AS count, ProfileID
FROM dbo.NhsEmail
GROUP BY ProfileID
ORDER BY Count DESC

Can someone give me the pesudo hql for a name query that would do this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 4:21 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
have i asked a stupid question not worthy of the courts attension?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 4:25 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
I can get my head round whether this is possible....im used to hibernate queries returning entity classes or sets of entity class, but in this case im returning a count aswell as a Profile...is this possible?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 9:20 am 
Regular
Regular

Joined: Tue May 31, 2005 3:18 pm
Posts: 117
Location: Houston
bosh wrote:
have i asked a stupid question not worthy of the courts attension?


chill. This forum doesn't have the typical 'holier-than-thou' attitude that most do.

I'm not very experienced with HQL, but what you'll want to do is get rid of the count, b/c your collection will tell you that. You'll also want to return various properties of the actual Person object, like doing "SELECT {Person.*} ..."

Hibernate In Action has some great examples, if you don't have that book I'd suggest picking it up. The link is at the top of the page.[/b]

_________________
------------------------------
Ben Scheirman
http://www.flux88.com


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