Quote:
No way. It is easy for you to call evict() and be explicit. This is simply not at all difficult.
While this is easy, it's also an extra call to the database. To make it worse, both calls to the database query unnecessary properties. Instead of one database call loading one column from the database, you have one database call loading all columns from the database (evict and load with 'heavy' class) then another database call to load all columns but one from the database (evict and reload 'light' class). I cannot leave the object as a heavyweight object because my original class has implicitly polymorphic subclasses and I'd get a cast exception if I left it like that.
I suppose for now the best idea is simply to decompose the table into two.
Support for 'lazy' properties would allow me to simply mark a property as lazy and forget about it. I hear it's on a list for possible future features. I suppose another option would be a 'smart' explicit polymorphic casting mechanism which would allow you to do something as follows:
HeavyObject heavy = (HeavyObject) session.explicitCast(light, HeavyObject.class)
This might explicitly evict the lightweight object and only load the properties that HeavyObject has. One could then cast it back to the lightweight object (this should require no database calls) to make the 'heavy' properties eligible for GC.
Etc etc...
I still think it would be better to have 'lazy' properties, though. Is this feature actually planned? Or is it just an item on a wish-list?