-->
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: best practices with relationships
PostPosted: Wed Dec 07, 2005 3:57 pm 
Newbie

Joined: Thu May 26, 2005 4:50 pm
Posts: 7
Hypothetically if I was creating a forum application that had many Topics with each Topic having possibly thousands of Posts. Say in the view that shows available Topics I wanted to give the date of the most recent Post (and other details of a Post such as the name of the poster, etc) under that topic. Does anyone have any examples or ideas on how to do this? Assuming that there is a one-to-many relationship from Topics to posts.

Should I try to add a property to Topic that stores the most recent Post? Maybe using a column formula to find it?

I haven't been able to find any examples of someone solving a similar problem. Any direction would be much appreciated.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 6:21 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
I would use HQL to retrieve the posts.

Cheers,
Radu


Top
 Profile  
 
 Post subject: thanks
PostPosted: Thu Dec 08, 2005 11:38 am 
Newbie

Joined: Thu May 26, 2005 4:50 pm
Posts: 7
I believe I understand how to get the Posts themselves to show in a list, but how do I, in the list of topics, find the most recent one.

So a view like this
Code:
Topic             Last Post

Trees             1/2/2005 - By Tim
Houses           1/4/2005 - By Bob


Is their an HQL way to join the Topics with the Posts finding the most recent Post only?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 4:35 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
Try giving something like this a shot ...

Code:
SELECT t, p
FROM Topic AS t
LEFT JOIN t.Posts as p
WHERE Size(t.Posts) = 0
OR p.Date = (
SELECT Max(p2.Date)
FROM Post AS p2
WHERE p2.Topic = t)


Top
 Profile  
 
 Post subject: Thanks!
PostPosted: Mon Dec 12, 2005 5:55 pm 
Newbie

Joined: Thu May 26, 2005 4:50 pm
Posts: 7
This works perfectly and is just what I wanted help understanding. I think I now have a much better grasp of HQL given that example.

Thank you for your time.


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.