Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate - filter child collection  RSS feed

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 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 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?

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!