Hi,
I would like to elaborate on that: karlchu is right when he says that the laziness of a collection/association is very situational.
But will you always be sure of the future requirements of your application ? Or have you at all times a good view on what your application is doing with your object ?
What I'm getting at here is that I do not think it is a good idea to set lazy="false" in your mapping files because you cannot override it in code. This way, you're not closing any doors, you'll have a little more coding to do to fetch the objects you want. Using an ICriteria query (or HQL) you can perfectly fetch your objects with their preloaded collections in code, and at the same time rest assured that, if needed, you still can load your objects without their collections.
The problem I had with lazy="false" is that it's easy to forget you ever set those collections/objects to lazy="false". After a while, you'll get performance problems on seemingly simple queries and only after seeing the SQL NHibernate emits, you'll understand that it's because you turned off lazy loading. And when your application is in production, it is not all too easy to turn on lazy loading on a frequently used object/collection because you always have the risk of getting lazy loading exceptions in places that worked fine until then.
_________________ Please rate this post if it helped.
X.
|