-->
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: Caching collections
PostPosted: Tue Apr 06, 2004 2:42 pm 
Beginner
Beginner

Joined: Mon Feb 09, 2004 3:15 pm
Posts: 34
I have a Group object which contains a Set of Question objects. Each Question object in turn has a Set of Answer objects.

I have a query that returns a Group object with its Set of Question objects and each Question with its Set of Answer objects.

I want to cache the results but I can't get it working. I have verified that ehcache.xml is set up correctly, i have verified that I am calling setCacheable(true) on the query object, and i have added the <cache> element in my mappings for all three classes (Group, Question, and Answer) as well in the <set> mappings for the Group and Question object.

Am i missing something here?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 6:02 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
how do you know the cache isn't used?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 8:06 pm 
Beginner
Beginner

Joined: Mon Feb 09, 2004 3:15 pm
Posts: 34
Well, actually, it is getting cached, but with the default settings...i.e. a timeout of 2 minutes.

In my ehcache.xml file i have all three objects specified for caching (Group, Question, and Answer).

And in all of their mappings i have included the <cache> tag in the <class> and <set> tags.

For some reason, it will cache itself using the default settings but not with what I specified in ehcache.xml.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 2:35 am 
Regular
Regular

Joined: Wed Mar 03, 2004 9:38 am
Posts: 70
You actually need to define 5 cache regions in the ehcache.xml file, not 3 (the collection caches require their own regions).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 5:00 pm 
Beginner
Beginner

Joined: Mon Feb 09, 2004 3:15 pm
Posts: 34
How do you define cache regions for collections?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 4:16 am 
Regular
Regular

Joined: Wed Mar 03, 2004 9:38 am
Posts: 70
bodhi wrote:
How do you define cache regions for collections?


In the same way you define other cache regions. The names are the same as for the collection properties in the parent class.

After some experimenting, I have come to the conclusion that collection caches contain one element per collection.

E.g. if you have an application with parent and child objects, and you expect the resident set size to be 100 parents and every parent contains on average 15 children, you would define caches as:

<!-- Parent objects -->
<cache name="com.foo.Parent"
maxElementsInMemory="100"
...other params... />

<!-- This is the collection cache, if the property is named
children, i.e. the Parent class has setChildren and
getChildren methods. Note that this cache does NOT
contain the actual elements of the collections, only
information about which id:s belong to which
collection. -->
<cache name="com.foo.Parent.children"
maxElementsInMemory="100"
... blah ... />

<!-- This cache contains the actual elements
of the collections -->
<cache name="com.foo.Children"
maxElementsInMemory="1500"
... blah blah />


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 5:26 pm 
Beginner
Beginner

Joined: Mon Feb 09, 2004 3:15 pm
Posts: 34
Thanks :)


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.