-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL for association
PostPosted: Fri Feb 15, 2008 1:54 am 
Newbie

Joined: Mon Jul 02, 2007 3:11 pm
Posts: 4
Hello,

I'm facing an issue in HQL.
I've Person bean and Set of Address bean inside it.
Person contains a field externalZipCode.
Address bean contains a field zipCode.
I want to get List of Person if either Person.externalZipCode = 94102 or Address.zipCode = 94102

My HQL goes like this -
--------HQL------
from Person p left join p.address as ad where p.externalZipCode = 94102 or ad.zipCode = 94102.
--------HQL------

This method returns List<Person>
The query runs successfully however I get ClassCastException when iterate over List<Person>

Any help would be greatly appreciated!

Thank you,

R.B.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 15, 2008 6:23 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
My HQL goes like this -
--------HQL------
from Person p left join p.address as ad where p.externalZipCode = 94102 or ad.zipCode = 94102


If above query is full query then, that query will return object array not Person that is the reason you are getting ClassCastException.

If you want achieve your requirement then use below HQL query


select p from Person p left join p.address as ad where p.externalZipCode = 94102 or ad.zipCode = 94102


Top
 Profile  
 
 Post subject: HQL for association
PostPosted: Fri Feb 15, 2008 1:54 pm 
Newbie

Joined: Mon Jul 02, 2007 3:11 pm
Posts: 4
Thank you so much for the reply.
I too thought so.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.