Assume a model with a user who has lots of subscriptions. The user class hence has a Set called subscriptions which holds all the users subscriptions and a hibernate mapping file exists for both user and subscription describing the association.
Great, I can load a user and access all his subscriptions!
The question I have is what if I only wanted to have all the active subscriptions?
A business rule exists which defines what an active subscription is, in this case its simply a property of type boolean in the subscription object.
Back to the question. Would I create a method in the User object which simply iterates over the Set of subscriptions and returns a subset containing only active subscriptions OR would I do create a hibernate query to return the active subscriptions for the user?
I am thinking that if initally I eagerly fetch the subscriptions for the user as an outer join, then iterating through the subscriptions would avoid me an additional trip to the database.
Does anyone have any recommendations here or pros and cons for each approach?