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

Hibernate - filter child collection

 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm back with yet another!!

I have a Criteria query where I call a parent/child relationship which his mapped as a parent class w/ a Set collection of child records.

To get them all I can call this, and it works fine:



This gives me all of the categories and all of the Announcment child objects in a HashSet.

Now, I need to restrict the number of records in the Set without affecting the parent object.

I was reading here on associations:

Hibernate Associations

...it says "You may easily specify constraints upon related entities by navigating associations using createCriteria()."

So, I tried this to limit the results of the "Announcements" collection



And, I must have understood because it filtered from the top down, not just the collection...so I only got one category and *all* of the child records in the Set.

How can I manipulate the results for child objects w/o changing how the parent is being queried?

Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic