The moose likes Object Relational Mapping and the fly likes A question about HQL cascade select Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "A question about HQL cascade select" Watch "A question about HQL cascade select" New topic
Author

A question about HQL cascade select

Lei Guoguo
Greenhorn

Joined: Mar 31, 2009
Posts: 26
hi, everyone, i have a question for HQL

we have two classes A and B, there have one-to-many relation, A is one, B is many.
and B had a field x.

question is: selected all the A's instance, required is B.x is equals 1.

please give the HQL

my answer is :
FROM A a WHERE a.b.id in (SELECT b.id FROM B b WHERE b.x = 1)

advance thanks everyone


I'm a chinese, my english is so bad, I need help. If you want to help me, you can send your question to my e-mail: lgg860911@yahoo.com.cn, I will help you, and improve my english. Thanks everyone.
Rahul Babbar
Ranch Hand

Joined: Jun 28, 2008
Posts: 210
Lei Guoguo wrote:
FROM A a WHERE a.b.id in (SELECT b.id FROM B b WHERE b.x = 1)


I think the following query should work fine.

FROM A a Inner Join a.b b where b.x = 1

Since your hbm file already has the association between the entities, you dont need to explicitly match A's id with B's id.
Remember that the use of Inner Select should be avoided and it should be used by Inner Join instead(as an Inner Join is faster)


Rahul Babbar
Lei Guoguo
Greenhorn

Joined: Mar 31, 2009
Posts: 26
Rahul, thank you very muck. i believe i was understood what you said
 
 
subject: A question about HQL cascade select
 
MyEclipse, The Clear Choice