-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Switch off lazy on certain fields of lazy class...
PostPosted: Mon Jul 17, 2006 9:37 pm 
Beginner
Beginner

Joined: Thu Dec 08, 2005 6:49 pm
Posts: 49
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...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 9:45 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The property element already supports the lazy attribute, for exactly this reason. Your sample code will work.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 1:47 am 
Beginner
Beginner

Joined: Thu Dec 08, 2005 6:49 pm
Posts: 49
Oh dear, I've been busted! I'm actually a NHibernate user and this feature hasn't been ported across yet.

My apologies and thanks for your quick response.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 2:14 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Upgrade to java.



;-)

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 2:29 am 
Beginner
Beginner

Joined: Thu Dec 08, 2005 6:49 pm
Posts: 49
How did I know you were going to say that!
Curious, do you have any idea at what version this property level proxying feature was implemented? Or perhaps the location of a changelog that I could look through?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 5:39 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Changelog.txt is in the root of all hibernate distributions. Don't know where it is in NHibernate dists.

According to the changelog, lazy attribute was added to property element in 3.0 alpha, dated 23/08/04. Wow, two years old already.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.