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

Parent and subcollection fetching

 
Andrei Antonescu
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am having the following HQL:


Children is a collection (let's say it is a set.) Each element in this collection has a status property which can be
1="child present" or 0="child deleted"

Can you please tell me how to fetch the parent and all the "present" children? I cannot navigate the association because my session is closed and I can't open it. I have tried to use "with" and fetch in the same HQL but Hibernate gives me an exception. I would like to use only 1 HQL select.


Thanks in advance
 
hayden wangg
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how about following:
select p from Parent p left join fetch p.children child where child.status='present'
 
Andrei Antonescu
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,

Thanks for posting. The solution is good but I doesn't solve my problem because I would like to fetch all the parents (it must return parent objects), and inside each parent only the status="present" children.
The posted query gives me the parents that have children with status="present" (and also fetches those childrens).

Can you please help me?

Thanks and sorry for the extra-restrictions
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic