-->
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: HQL for min() over a referenced collection
PostPosted: Wed Nov 21, 2007 2:06 pm 
Newbie

Joined: Tue Nov 20, 2007 8:34 am
Posts: 3
Hi,

i am looking for a way to get the minimal date of a collection of share prices for a given company. It should be something like:

Code:
select min(c.sharePrices.date) from Company c where c = :company


But I get an error message:

Code:
QueryException: illegal attempt to dereference collection [company0_.id.sharePrices] with element property reference [date]


Also the intuitive

Code:
select min(s.date) from SharePrice s, Company c where c = :company and s in c.sharePrices


does not work, because it is translated to:

Code:
select min(shareprice0_.date) as col_0_0_ from SharePrice shareprice0_, Company company1_, Company_SharePrice shareprice2_, SharePrice shareprice3_ where company1_.id=shareprice2_.Company_id and shareprice2_.sharePrices_id=shareprice3_.id and company1_.id=? and (shareprice0_.id in (.))


I am relatively new to Hibernate. Can anybody give me a hint on how to do this query properly?

Thanks!
korpe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 3:19 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Not tested the solution below give it a try,

select min(DATE as {c.sharePrices.date}) from Company c where c = :company

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 26, 2007 8:04 am 
Newbie

Joined: Tue Nov 20, 2007 8:34 am
Posts: 3
Hi ramnath,

thanks for your help. Unfortunately that doesn't work neither. I get the following error message:

Code:
org.hibernate.QueryException: unexpected char: '{' [select min(DATE as {c.sharePrices.date}) from de.fraunhofer.iais.kd.sentigraph.model.Company c where c = :company]


Any other ideas?


Top
 Profile  
 
 Post subject: new try
PostPosted: Tue Nov 27, 2007 8:01 am 
Newbie

Joined: Tue Nov 20, 2007 8:34 am
Posts: 3
now I tried to use a left outer join:

Code:
select min(s.date)
from Company_SharePrice cs, Company c
left outer join SharePrice s with cs.sharePrices_id=s.id
where c = :company and cs.Company_id = c.id


But that doesn't work, because Company_SharePrice is no class, and thus, it is not mapped:

Code:
org.hibernate.hql.ast.QuerySyntaxException: Company_SharePrice is not mapped [select min(s.date)...


Do I have to write a SQL-Query here? Any hints?

Thanks,
korpe


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.