Is it possible to switch off lazy loading for certain fields in a lazily loaded class? That is, certain fields other than the primary keys are fetched upfront, and touching those properties doesn’t cause the remainder of the object to be loaded.
For example, let’s say I have a very large contact management database in which contacts are constantly being added and removed. For auditing purposes, contacts are given a CreateDate when added and a RemoveDate when deleted (rather than being physically deleted).
I’d really like to be able to touch the ID, Name, CreateDate and RemoveDate fields without causing the object to be loaded.
This is not too hard to do manually at the top level using HQL to get the upfront fields and changing the accessors on those properties. But it would be really cool if there was a way to do this so that it would automatically work on collections, etc.
I guess what I’m looking for is the lazy attribute on property mappings.
Code:
class Contact {
property ID;
property Name;
property CreateDate;
property RemoveDate;
//lots of lazy properties
}
<class name="Contact" lazy="true">
<id name="ID">
<generator class="identity" />
</id>
<property name="Name" lazy="false" />
<property name="CreateDate" lazy="false" />
<property name="RemoveDate" lazy="false" />
<!-- lots of lazy properties -->
</class>
The reason why I need my collections to be filled with every object (even if they aren’t currently valid, as per the CreateDate/RemoveDate fields) is that I’m writing a windows UI application with a plugin API. The API exposes top level entities in collections that must contain all objects regardless.
This is probably one of those things that would open up a can of worms...