Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » (no subject)
(no subject) [message #687431] Thu, 09 June 2011 22:42 Go to next message
Eclipse UserFriend
Originally posted by: <forums-noreply

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 #687433 is a reply to message #687431] Fri, 10 June 2011 20:44 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
I think you should make this a join to the MobileProvider entity (assuming that's the name), and use the special
elements function, something like this:
select count(asset.ID) from Asset as asset, MobileProvider as mp where mp in elements(asset.StateInfo) and
mp.Name='Vodafone'

Hibernate/HQL has some nice collection functions which you can use in the where clause.

gr. Martin

On 06/10/2011 12:42 AM, forums-noreply@eclipse.org wrote:
> 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
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Previous Topic:Databinding on DateTime widget
Next Topic:(no subject)
Goto Forum:
  


Current Time: Sun Sep 15 16:54:56 GMT 2019

Powered by FUDForum. Page generated in 0.01626 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top