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.
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, thank you very muck. i believe i was understood what you said
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.