-->
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: Need help with an HQL query
PostPosted: Thu Sep 09, 2004 2:10 am 
Regular
Regular

Joined: Tue Jun 08, 2004 8:24 am
Posts: 57
I'm having trouble formulating an HQL query in hibernate 2.1.

I have a data structure where a FileInformation can have many corresponding FileData.
A FileData has a version date that gets updated every time a new version of the file data is stored on the system.

What I want to do is fetch out a list of FileInformation along with the most recent version of the file data for each, which does not exceed a specified version date.

I've tried the following query, which fails because it doesn't like an aggragator in the where clause.

select
fileInfo,
fileData,
max(fileData.versionDate)
from
FileInformation as fileInfo,
FileData as fileData
where
fileData.fileInformation = fileInfo and
fileData.versionDate = max(fileData.versionDate)
group by
fileInfo
having
fileData.versionDate <= :versionDate



I've also tried this version, which fails with an exception: net.sf.hibernate.QueryException: , expected in SELECT.
I'm guessing that HQL does not allow aliasing of aggregate function results.

select
fileInfo,
fileData,
max(fileData.versionDate) maxDate
from
FileInformation as fileInfo,
FileData as fileData
where
fileData.fileInformation = fileInfo and
fileData.versionDate = maxDate
group by
fileInfo
having
fileData.versionDate <= :versionDate


Is there any other way to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 4:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You need a subselect for this. I recommend reading a good book on SQL, since HQL is conceptually similar.


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.