-->
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.  [ 1 post ] 
Author Message
 Post subject: How to check if a collection was modified without loading it
PostPosted: Wed Jan 16, 2008 2:21 am 
Beginner
Beginner

Joined: Sun Apr 09, 2006 9:07 pm
Posts: 24
Hibernate version: 1.2.0 GA

I have a lazy-loaded collection, which is fairly expensive to load. I'd like to cache the number of elements in that collection elsewhere. The logical place to update the cache seemed to be whenever the parent object is saved, so I added code like this:

if (NHibernateUtil.IsInitialized(parent.Collection))
{
cachedCount = parent.Collection.Count;
}

I wanted to avoid loading the collection when it wasn't necessary and figured that if it wasn't initialised then it couldn't have been modified, so there's no point updating the count. After some debugging, it turns out I was wrong: NHibernate adds a "queued write" and marks the collection as "dirty" while it's still not "initialised".

Is there any way that I can check whether the collection has been modified since it was loaded, but without loading it if it hasn't been loaded already?


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

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.