-->
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: help with hql --use of with clause
PostPosted: Wed Feb 09, 2011 2:57 pm 
Newbie

Joined: Mon Dec 08, 2008 4:27 pm
Posts: 4
I've the below sql query and I need corresponding hql.

Code:
select * from cost_pool c left outer join sub_cost_pool s on c.cost_pool_code=s.cost_pool_code and s.model_id=1 where c.cost_pool_code='BD-100'


Cost pool has a collection(sub_cost_pool) as a property. I need to filter the collection based on model_id
It should return one object with a filtered collection
I tried this

Code:
from CostPool c left join c.subCostPools sc with sc.model.modelId=:modelId where c.costPoolCode=:costPoolCode


It didn't work...it was returning a list of 2 objects (1 costpool with unfiltered collection, 1 subcostpool).

Please help me. I already spent couple of hours on this. I tried using filters, it didn't help me.


Top
 Profile  
 
 Post subject: Re: help with hql --use of with clause
PostPosted: Thu Feb 10, 2011 5:06 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
Hi,

Can you post the hibernate mapping of the 2 classes?


Top
 Profile  
 
 Post subject: Re: help with hql --use of with clause
PostPosted: Thu Feb 10, 2011 11:40 am 
Newbie

Joined: Mon Dec 08, 2008 4:27 pm
Posts: 4
overmeulen wrote:
Hi,

Can you post the hibernate mapping of the 2 classes?


Hey, I got the solution, there were two issues:
1. I was using hibernate 3.x which doesn't support with clause.
2. And it seems, hql doesn't support condition on fetching collections.

So, I upgraded to 3.5 and used filters on collection and it worked awesome..

Thanks overmeulen for replying.


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.