-->
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: subselect in query
PostPosted: Tue Feb 19, 2008 1:32 pm 
Newbie

Joined: Mon Feb 18, 2008 4:46 am
Posts: 6
Hi,

Can i write an HQL query which defines subselect in it.
explaining:

lets assume i have two entites A and B and the relation is many-to-many.

A
---
int x;
int y;

"lazy"
Collection getB();


------------------------

i want to write something like:
select a
from A a
inner join subselect a.b
where a.x =0;



like i can write (if i want to get b eagerly)
select a
from A a
inner join fetch a.b
where a.x =0;



can i do something like that ??

many thanks,
Eran.


Top
 Profile  
 
 Post subject: Re: HQL: subselect in query
PostPosted: Tue Feb 19, 2008 3:27 pm 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Both the queries are valid. But the difference is:
eranmiz133 wrote:
i want to write something like:
select a
from A a
inner join subselect a.b
where a.x =0;


Here collection b is lazy loaded and when ever you access it another query is issued to fetch each element of b.

eranmiz133 wrote:
like i can write (if i want to get b eagerly)
select a
from A a
inner join fetch a.b
where a.x =0;



Here b is fetched eagerly with join.

Depending on the requirement - to use 'b' or not, you can write either of the queries.


Top
 Profile  
 
 Post subject: can i write subselect in a query ?
PostPosted: Wed Feb 20, 2008 8:03 am 
Newbie

Joined: Mon Feb 18, 2008 4:46 am
Posts: 6
thank u for the reply.

i checked it (the "subselect"), and it is not legal - unless the syntax is not correct.

what i wrote (with the subselect) is just an example for the query syntax
i am looking for.

i want also for the subselect query to execute on the HQL query itself,
and not later when it is needed (through lazy loading).
i am looking for something like "eager subselect" in the HQL query - meaning the data will be retrieved in another query -
so, the duplicates i am suffering from, will be remove.


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.