I currently have the requirement to lazy load a collection based on some date criteria.
i.e. I may have a collection of details that are amount sensitive and I want to be able to load up a sub set of that collection (ones that are above a certain amount).
I can use a filter such in the manner of
Code:
session.filter(persistentCollection, "where this.amt >= ?", new Object[]{new BigDecimal(160)}, new Type[]{Hibernate.BIG_DECIMAL});
This is all fine and dandy in the case that I can retrieve an ArrayList of elements that represent these records.
But what I really want to do is that I have a bidirectional association (consisting of a Set) that I want to lazy load at some point after my object is originally loaded (via LOCKing it back to a Session). During this I want to have my collection initialized with the sub set of my data.
With the sub set I want to be able to add, update, delete and only have the records within this sub set affected (via cascading from my parent object).
Is this even possible? I've been playing around with taking the returned collection and then constructing a new Set passing in the results from the session.filter call and setting that back on my parent object.
I've had some mixed success with this so far, i.e. if I am only updating the records it all seems fine. Adding a record seems that it would work as well. I'm having some issues with removing an existing record but that might be related to the fact that it can't seem to find my object in the HashSet. Even if it does manage to work I am terrified that it will create random havoc somewhere down the line.
I guess in the end of it all would be, is there an existing pattern for what I am attemping to accomplish.