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
|