Mike,
Thanks, your answer is helpful, and I think it may solve my problem.
It seems, though, that there ought to be a more seamless way to do what I'm trying to do. Using filters allows me to do something like this:
Parent parent = session.load(...);
session.enableFilter("byDate").setParameter("date", date1);
Child child1 = parent.getChild(date1);
session.enableFilter("byDate").setParameter("date", date2);
Child child2 = parent.getChild(date2);
But ideally I'd like to do the above, without having to set the filter parameters each time I want to retrieve a new child from the parent. (Maybe in the persistence layer I don't know exactly what children I'll need, and when I'm calling parent.getChild(), I'm not in Hibernate-aware code, so it's not convenient to deal with filters.) What would be cool is if every time I call getChild(), Hibernate could anticipate whether it needs to go to the database to retrieve another batch of children.
Oh well, like I said, I think I can do what I need with filters. Thanks for your response.
|