• Post Reply Bookmark Topic Watch Topic
  • New Topic

A question about HQL cascade select

 
Lei Guoguo
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Lei Guoguo
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul, thank you very muck. i believe i was understood what you said
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!