Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic