Chuinnim Blog

Wednesday, December 07, 2005

Hibernate Lazy Loading & Session-In-View Pattern

Hi everyone, I'm really new to blogging but interested in seeing if anyone will even see this... So I've been thinking lately... that maybe the whole Hibernate lazy loading + session-in-view pattern is sorta, kinda, not all that great of an idea??? It strikes me as being a 'feature' that people might want to use as a result of not taking the time to define use cases ahead of time and then code accordingly. What do you all think? Has this opinion already been expressed elsewhere? I feel like it would be better in many ways, to clearly define methods say, in a DAO, to distinguish when one might want just a parent class vs. wanting a parent and it's children, or just the children by themselves. In fact, I wonder if it's not a bad idea to generally commit to what it is you want, right in the DAO methods themselves. So if you wanted a parent, you ask the DAO for a parent. If you want its kids, you ask the DAO for its kids. If you want a parent WITH its kids, then you should ask the DAO for a parent WITH its kids. I'm just not real hip on the idea that, "well, I know I want the parent right now, and.... maybe... ummmm, I might want the kids later.... so IF I decide I want them later down the road, like in a JSP... I could always lazy load them." That just feels like bad design to me. Not to mention the fact that I've seen a little bit of what can go wrong with that mess. Albeit, if you're using an ORM framework that support lazy loading and in which you can implement session-in-view for a web app, you're not likely to change to another ORM midstream (probably), but if you did, and the new one doesn't support either of those features... now what? I don't know though, maybe that pattern's getting us to a more advanced coding model where data access is truly transparent and you don't have to think about demarcations of when and where data's coming from. Maybe...

0 Comments:

Post a Comment

<< Home