-->
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.  [ 7 posts ] 
Author Message
 Post subject: object.children.size() possible without initializing?
PostPosted: Thu Apr 22, 2004 3:54 pm 
Beginner
Beginner

Joined: Wed Sep 10, 2003 5:34 pm
Posts: 36
Location: New York, NY
After reading and experimenting with the 2nd level cache quite extensively, I've gotten to a situation where I want to simply count the number of children of an object, but not initialize those children. In fact, I have the join cached in a collection cache and it would be totally fine with me if I could simply get a size() call from the collection in the cache (i.e. no actual data from the child objects). However, I can't seem to find how to do this. Even when the getChildren().size() results in a collection cache hit the full list of child objects is initialized to complete the size() call.

Other things I have tried:

1. SQL only solution - didn't work due to performance and SQL version limitations
2. Making the child object a proxy - didn't work since the full objects still seem to get initialized by the size() call
3. Just getting by with caching everything, including the child objects - doesn't work in my case because there is too much data, and even loading from cache those child objects is too slow in this use

Does anyone have any ideas or alternate ways to get a size of that collection without initializing it?

Thanks for any advice.

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 3:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
http://www.hibernate.org/118.html#A4


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 4:17 pm 
Beginner
Beginner

Joined: Wed Sep 10, 2003 5:34 pm
Posts: 36
Location: New York, NY
Thanks for the quick reply Michael, I should have been more specific. That method came under #1 of the methods I tried since it generates SQL to count the size of the collection. Unfortunately the table that containts the elements of that collection is so large that running the necessary series of "select count(*)" statements is just too slow.

So really, what I seem to need specifically is a way to get a size() of the collection that's in the collection cache without initializing the underlying collection and it's objects. That seems to be the only way that'll be fast enough in this case.

Thanks for any other input.

Matt

P.s. Just as a quick background on the problem, on application startup I cache all the objects related to this problem so when they're accessed later they achieve 100% cache hit rates. However, it's too slow even to initialize the child collection from the cache when really all I need is the size of the collection. So that's how I got to this point.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 9:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I have done this and some other related things a few times using a formula property. In terms of performance it works out much better.

http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s1-7; check out the formula attribute


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 23, 2004 1:45 am 
Beginner
Beginner

Joined: Wed Sep 10, 2003 5:34 pm
Posts: 36
Location: New York, NY
Thanks for the info Steve, I hadn't seen the formula attribute before. One thing I'm concerned about is caching that object with the formula property, and whether that property will become incorrect as the tables the property is based on change. Also, the 2.1.1 release notes say:

* don't cache objects with formula properties immediately after insert/update

So does that mean that no object with a formula will be cached? I guess I'm just not clear on cache interaction with the forumla property in general.

Thanks for the tip, let me know if you have any experience with the above.

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 23, 2004 2:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, it means the object will be evicted and recached next time it is used.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 23, 2004 11:33 am 
Beginner
Beginner

Joined: Wed Sep 10, 2003 5:34 pm
Posts: 36
Location: New York, NY
Gavin,

Does it make sense to you that perhaps a size() or empty() call to a persistent collection should return the size of the cached array if found rather than initializing the whole collection? I'm figuring that the size() call initializing the colleciton comes from the days of no second level collection cache and is probably still around since it's mentioned in the docs as a way to initialize collections. Is that correct?

Is there another reason for it to still happen that I'm not seeing from the code? Thanks for the help.

Matt


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.