-->
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.  [ 2 posts ] 
Author Message
 Post subject: Help in HQL Query
PostPosted: Thu Dec 11, 2008 12:25 pm 
Newbie

Joined: Thu Dec 11, 2008 12:20 pm
Posts: 2
I have a very simple model consisting of Forum, Threads and Posts. A Forum can have multiple Threads and a Thread can have multiple Posts. I have everything setup.
Now I need to write a query to get me the following:
Forum Name, Forum Description, Number of Threads in the Forum, Number of Posts in the Forum and the Time when the last post was made on that Forum.
I can write this query in SQL easily but am stuck in HQL. Can anyone help out with how this query can be written, please bear with me as I am still learning.


Top
 Profile  
 
 Post subject: Re: Help in HQL Query
PostPosted: Thu Dec 11, 2008 12:27 pm 
Newbie

Joined: Thu Dec 11, 2008 12:20 pm
Posts: 2
The nearest I came was this query
select p.BelongsToThread.BelongsToForum.Name, p.BelongsToThread.BelongsToForum.Description, count(p), max(p.PostedAt)
from Post p
right outer join p.BelongsToThread.BelongsToForum
group by p.BelongsToThread.BelongsToForum.Name, p.BelongsToThread.BelongsToForum.Description

This gives me everything except the number of threads in the forum.


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