-->
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.  [ 10 posts ] 
Author Message
 Post subject: Second Level Cache Question
PostPosted: Tue Dec 09, 2003 5:10 pm 
Newbie

Joined: Tue Dec 09, 2003 4:45 pm
Posts: 14
Hi all,

I'm somewhat new to Hibernate, so I appologize if this is a dumb question...

I'm using Hibernate 2.1 and I am trying to get the Second Level Cache working. I use the default cache provider, which leads to the following being output to System.out when the hibernate configuration is loaded:
- cache provider: net.sf.ehcache.hibernate.Provider
- instantiating and configuring caches
As far as I can tell, the ehcache provider is configured correctly. FYI, in ehcache.xml, I have the following cache entry

<cache name="test.TestModel"
maxElementsInMemory="10000"
eternal="true"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="false"
/>

This cache corresponds to class test.TestModel and accompanying config file TestModel.hbm.xml. The element <cache usage="read-only"/> appears in the model config file

To test the caching, I create two distinct Hibernate sessions and iterate through the results of session.iterate(...) for each session, where the iterate method is passed a query that will return ~1000 records. I have also set hibernate.show_sql to true so that I can see SQL being sent to my database. As expected, when iterating using the iterator created by the first session, one query is executed that returns the ids of all matching objects, and ~1000 additional queries are executed to load the object properties. My concern is that the same output is generated for the second iterator; I had thought that only the query that selects all of the object ids would run and that the others would not run because the objects had all been loaded into the cache.

I would really appreciate it if anyone can explain what I am doing incorrectly here. I can provide additional code to clarify this if need be. Thanks in advance for your help.

_________________
Mike Davison


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 6:44 pm 
Beginner
Beginner

Joined: Sun Sep 21, 2003 12:19 am
Posts: 40
If I am not mistake the query has to go to DB. Only the furthur references (such as getXXX on the object returned from the query) will result cache look up.

I thought iterate() only issue query to get object's unique id then only user iterate through it, will then result cache hit. But apparently it is NOT true, it seems from my 5 minutes debug, it seems it just sends entire query to db rather than just send 'from' clause to the db and take extract the id then return (which is preferable way for me, but I guess it involves intensive query parsing).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 8:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
There is a timstamping bug in the build of the EHCache provider that shipped with Hibernate 2.1rc1. It could cause this. This bug is fixed in CVS.


Top
 Profile  
 
 Post subject: EHCache in CVS
PostPosted: Wed Dec 10, 2003 3:36 pm 
Newbie

Joined: Tue Dec 09, 2003 4:45 pm
Posts: 14
Thanks for both of your replies. Gavin, you mentioned that there is a bug in the EHCache implementation that shipped with Hibernate 2.1rc1 and that the bug has been fixed in CVS. Just to be clear, I need to pull the latest stable build of EHCache from the EHCache CVS repository at sourceforge, right? If not, could you please point me in the right direction? Thanks again.

_________________
Mike Davison


Top
 Profile  
 
 Post subject: Problem Solved
PostPosted: Wed Dec 10, 2003 4:00 pm 
Newbie

Joined: Tue Dec 09, 2003 4:45 pm
Posts: 14
Gavin, I followed my own instructions and pulled the latest ehcache source and rebuilt the ehcache jar and the caching works perfectly. Thanks again.

_________________
Mike Davison


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 5:25 pm 
Beginner
Beginner

Joined: Sat Dec 06, 2003 5:38 pm
Posts: 27
For other readers, the build marker ehcache 0.6 has the fix in it. You don't have to build from CVS..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 1:53 am 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
Where did you pick up that jar? I downloaded a 162K file called ehcache-0.6.gz and it only seemed to have a /docs directory. I eventually picked up the CVS version and built from there.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 9:23 am 
Regular
Regular

Joined: Mon Sep 08, 2003 4:53 am
Posts: 70
Location: Germany
If you download from http://prdownloads.sourceforge.net/ehcache/ehcache-0.6.tgz?download, than there's a ehcache.jar file, too.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 1:05 pm 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
That is the same link I used to download the file. Is it a seperate download? I tried unzipping that with cygwin's gunzip/unzip and see only /docs... I also tried WinZip with the same result. Maybe this is just a Windows thing.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2003 6:30 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Use the one in hibernate 2.1final

_________________
Emmanuel


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