[Hibernate] HQL statement for one-to-many [message #681821] |
Thu, 09 June 2011 18:42  |
Eclipse User |
|
|
|
Got a newbie HQL/SQL question for you all.
I have the following HQL statement
select count(ID) from Asset as asset where asset.StateInfo.MobileProvider.Name='Vodafone'
The Asset->StateInfo reference is one-to-many and the rest are one-to-one. This query generates a QueryException:
org.hibernate.QueryException: illegal attempt to dereference collection [asset0_.`id`.StateInfo] with element property reference [MobileProvider] [select count(ID) from Asset as asset where asset.StateInfo.MobileProvider.Name='Vodafone']
I'm sure this is because I'm doing the asset.StateInfo reference in the query all wrong. Would some kind soul please set me on the right path?
Cheers,
mike
|
|
|
|
|
|
|
Re: [Hibernate] HQL statement for one-to-many [message #685236 is a reply to message #685183] |
Fri, 17 June 2011 01:01   |
Eclipse User |
|
|
|
I have not tried it but see this part of the HQL chapter in the Hibernate docs:
HQL functions that take collection-valued path expressions: size(), minelement(), maxelement(), minindex(), maxindex(), along with the special elements() and indices functions that can be quantified using some, all, exists, any, in.
you can try maxelement I guess in the whereclause:
select count(asset.ID) from Asset as asset, MobileProvider as mp where mp = maxelement(asset.StateInfo) and mp.Name='Vodafone'
Can you let me know if this works (cause then I know it to)?
gr. Martin
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04637 seconds