Im looking to create a generic DAO to handle CRUD in my hibernate app. My entities have most associations as LAZY fetching. But I find in order to have hibernate be efficient as possible with the SELECTs I have to create multiple methods on my DAOs. Here's what I mean:
Entity A has two associations. Sometimes I want to retrieve this entity without loading the associations and sometimes I want it fully populated, so I'd put two methods on the DAO:
getWhatever()
getWhateverWithLoadedAssociations()
and I'd have two different queries, one without join fetch, and the other with join fetch. The result is hibernate always does a single select regardless if its LAZY or not, because I know what I want to get up front.
The problem with this is, while saving a SELECT or two, its adding complexity due to the number of methods.
So is this being to extreme? Should I just have getWhatever() and just let hibernate do another select when I need the data for the association, even though I could have saved from not doing that SELECT?
I hope this is not too confusing. I'm trying to figure out the cost of number of SELECTS due to lazy loading, vs. code complexity
thanks