-->
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 issue
PostPosted: Mon Feb 28, 2011 9:29 pm 
Newbie

Joined: Mon Dec 06, 2010 8:37 pm
Posts: 2
Hi,

I have a Data Tbl and employee tbl.

Data Tbl:

Id.....employeeId..... data.....Status
1..... e_1...............abc.....Active
2..... e_1.......... ....xyz.....Inactive
3..... e_2...............123.....Active
4.....e_3...............123.....Inactive

Employee Tbl:

Id .....Name
e_1 .....J
e_2 .....K
e_3.....L

when i run the following query "select distinct e from Employee as e join e.datas as dt where dt.status='Active' order by e.Name asc" i correctly get only employees with active status, e1 & e2.

The issue i'm facing is if loop thro the above employee object ,say e_1 , my Data object is off size 2 instead of size1. any clue on solving it?

-thanks,
prakash,
UC davis


Top
 Profile  
 
 Post subject: Re: HQL issue
PostPosted: Tue Mar 01, 2011 8:54 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Try to use "join fetch" otherwise the data collection gets initialized by an extra query without the filter.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: HQL issue
PostPosted: Tue Mar 01, 2011 12:38 pm 
Regular
Regular

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

Is the "fetch" keyword really necessary here?
I thought that it only specified "When" the data had to be extracted from the DB ...
Can it work using "join ... with" instead of "join ... where" in the below example?


Top
 Profile  
 
 Post subject: Re: HQL issue
PostPosted: Tue Mar 01, 2011 1:18 pm 
Newbie

Joined: Mon Dec 06, 2010 8:37 pm
Posts: 2
hi,

the syntax "join fetch" did the trick. Thanks!

I tried the syntax "join.. with" instead of "join.. where" and it didn't apply the filter on the collections.

Thanks,
prakash


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.