Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: ehcache configuration not working?

  1. #1
    Join Date
    Aug 2006
    Posts
    11

    Default ehcache configuration not working?

    Hibernate version: 3.2.0
    Ehcache version: 1.2.4
    Spring version: 2.0.3

    I'm having issues with getting the "caching" behaviour to work. I've just mapped a simple Country business object to my country table in the database and enabled ehcache to cache on this particular table. However, when i load up my page that calls the function to get all countries, there does not seem to be any performance increase after the first hit like i would expect. The outputted log times are as follows (according to the code i've pasted below).

    ****** Get Country List exec time: 2590ms -- 236 items ******
    ****** Get Country List exec time: 2109ms -- 236 items ******
    ****** Get Country List exec time: 2344ms -- 236 items ******
    ****** Get Country List exec time: 2032ms -- 236 items ******

    When i start up my Resin, the logs show that my ehcache provider is enabled, and i see the log message "- read-only cache configured for mutable class: com.gdi.core.businessobjects.Country" so i would assume my Country should be returning from cache after first hit. Is there anything i'm missing or should be doing differently? I've posted details of my current setup including the source code that is getting the country list below.

    Also, is there anywhere i can dig into the SessionFactory... or ehcache manager for statistics during each call? I'd like to somehow know if the system is actually caching or not caching the results. I'm just assuming it's not caching based on the response time between each calls on such a simple query. Most examples i've seen calls that take 1800 ms reduced down to 50-100 ms so i'm expecting a level of improvement in performance around this factor in my application as well.

    Country Business Object hbm.xml mapping

    Code:
    <?xml version="1.0"?> 
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
    <!-- Generated 10-Aug-2006 12:24:19 PM by Hibernate Tools 3.2.0.beta6a --> 
    <hibernate-mapping> 
        <class name="com.gdi.core.businessobjects.Country" table="country"> 
            <id name="id" type="int"> 
                <column name="id" /> 
                <generator class="sequence"> 
                   <param name="sequence">country_id_seq</param> 
                </generator> 
            </id> 
            <property name="name" type="string"> 
                <column name="name" length="32" not-null="true" /> 
            </property> 
            <property name="code" type="string"> 
                <column name="code" length="5" not-null="true" /> 
            </property> 
            <property name="numericCode" type="string"> 
                <column name="numericcode" length="3" not-null="true" /> 
            </property> 
            <property name="alphaCode" type="string"> 
                <column name="alphacode" length="3" not-null="true" /> 
            </property> 
        </class> 
    </hibernate-mapping>

    in my spring/hibernate configuration session factory definition

    Code:
          <property name="hibernateProperties"> 
             <props> 
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> 
                <prop key="hibernate.show_sql">false</prop> 
                <prop key="hibernate.generate_statistics">true</prop> 
    
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> 
                <prop key="hibernate.cache.provider_configuration_file_resource_path">gdi-ehcache.xml</prop>             
                <prop key="hibernate.cache.use_query_cache">true</prop> 
             </props> 
          </property>          
    
          <property name="entityCacheStrategies"> 
             <props> 
                 <prop key="com.gdi.core.businessobjects.Licensee">read-only</prop> 
                 <prop key="com.gdi.core.businessobjects.Country">read-only</prop> 
                 <prop key="com.gdi.core.businessobjects.CountryRegion">read-only</prop> 
              </props> 
          </property>
    Code in my DAO which extends HibernateDaoSupport

    Code:
            return getHibernateTemplate().executeFind(new HibernateCallback() 
            { 
                public Object doInHibernate(Session session) throws HibernateException, SQLException 
                { 
                    long startTime = System.currentTimeMillis(); 
                                    
                    Query query = session.createQuery("from Country order by name asc");                                
                    List list = query.list(); 
                                    
                    long endTime = System.currentTimeMillis(); 
                    System.out.println("****** Get Country List exec time:  " + (endTime - startTime) + "ms -- " + list.size() + " items  ******" );                
                                                    
                    return list; 
                } 
            } 
            );
    EhCache definition:

    Code:
    <ehcache>  
    
    	<diskStore path="java.io.tmpdir"/>
    
    	<defaultCache
    	    maxElementsInMemory="10"
    	    eternal="false"
    	    timeToIdleSeconds="120"
    	    timeToLiveSeconds="120"
    	    overflowToDisk="true"
    	    diskPersistent="false"
    	    diskExpiryThreadIntervalSeconds="120"
    	    memoryStoreEvictionPolicy="LRU"/>
    
    	<cache name="com.gdi.core.businessobjects.Licensee"
    	    maxElementsInMemory="500"
    	    eternal="false"
    	    timeToIdleSeconds="120"
    	    timeToLiveSeconds="120"
    	    overflowToDisk="true"/>
    
    	<cache name="com.gdi.core.businessobjects.Country"
    	    maxElementsInMemory="300"
    	    eternal="false"
    	    timeToIdleSeconds="120"
    	    timeToLiveSeconds="120"
    	    overflowToDisk="true"/>
    	    	  	    
    	<cache name="com.gdi.core.businessobjects.CountryRegion"
    	    maxElementsInMemory="100"
    	    eternal="false"
    	    timeToIdleSeconds="120"
    	    timeToLiveSeconds="120"
    	    overflowToDisk="true"/>	    
    
    </ehcache>
    Name and version of the database: PostGres 7.4

    Debug level Hibernate log excerpt:

    - Second-level cache: enabled
    - Query cache: enabled
    - Cache provider: org.hibernate.cache.EhCacheProvider
    - Optimize cache for minimal puts: disabled
    - Structured second-level cache entries: disabled
    - Query cache factory: org.hibernate.cache.StandardQueryCacheFactory
    - Statistics: enabled
    - Deleted entity synthetic identifier rollback: disabled
    - Default entity-mode: pojo
    - building session factory
    - read-only cache configured for mutable class: com.gdi.core.businessobjects.Licensee
    - read-only cache configured for mutable class: com.gdi.core.businessobjects.CountryRegion
    - read-only cache configured for mutable class: com.gdi.core.businessobjects.Country
    - Not binding factory to JNDI, no JNDI name configured
    - starting update timestamps cache at region: org.hibernate.cache.UpdateTimestampsCache
    - Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.
    - starting query cache at region: org.hibernate.cache.StandardQueryCache
    - Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.

  2. #2
    Join Date
    Mar 2007
    Posts
    515

    Default

    Try setting setCacheable(true) on the Query object:
    Code:
    Query query = session.createQuery("from Country order by name asc").setCacheable(true);

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

  4. #4
    Join Date
    Aug 2006
    Posts
    11

    Default

    After looking through the log files from the sessionfactory's statistics log summary. It appears the application is loading from cache, however the overall execution time in that java method still makes me wonder why the performance gain is not that much better than expected.

    i did a trial run of 4 hits to get my country list through the DAO mentioned in the beginning of this thread and i got the results based on the execution time in the java code.

    ****** Get Country List exec time: 2562ms -- 236 items ******
    ****** Get Country List exec time: 2016ms -- 236 items ******
    ****** Get Country List exec time: 2175ms -- 236 items ******
    ****** Get Country List exec time: 2259ms -- 236 items ******

    the log dump of the session factory gives these numbers below. It appears the countries are loaded into cache, and it appears that the DAO is doing a hit on the cache to load the objects. So it seems all working, however i still don't see how the exectuion time can not change for the DAO call. I'm expecting results differences outlined in the article i read at
    http://www.devx.com/dbzone/Article/29685/1954?pf=true. Unless i did something wrong, this doesn't seem like it should be the correct behaviour of retrieving a cached list of simple Country objects. I'm still relatively new to hibernate, so all these stats aren't completely familiar to me, maybe someone who has had experience with a similar configuration as mine can enlighten me as to what i can be missing. Thanks in advance.

    Code:
    after 1st hit
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - Logging statistics....
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - start time: 1175192124093
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - sessions opened: 1
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - sessions closed: 1
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - transactions: 1
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - successful transactions: 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - optimistic lock failures: 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - flushes: 1
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - connections obtained: 1
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - statements prepared: 1
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - statements closed: 1
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - second level cache puts: 236
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - second level cache hits: 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - second level cache misses: 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - entities loaded: 236
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - entities updated: 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - entities inserted: 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - entities deleted: 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - entities fetched (minimize this): 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - collections loaded: 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - collections updated: 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - collections removed: 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - collections recreated: 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - collections fetched (minimize this): 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - queries executed to database: 1
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - query cache puts: 1
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - query cache hits: 0
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - query cache misses: 1
    2007-Mar-29 11:15:40 [StatisticsImpl] INFO   - max query time: 2000ms
    
    after 2nd hit
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - Logging statistics....
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - start time: 1175192124093
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - sessions opened: 2
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - sessions closed: 2
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - transactions: 1
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - successful transactions: 0
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - optimistic lock failures: 0
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - flushes: 2
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - connections obtained: 1
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - statements prepared: 1
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - statements closed: 1
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - second level cache puts: 236
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - second level cache hits: 236
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - second level cache misses: 0
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - entities loaded: 236
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - entities updated: 0
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - entities inserted: 0
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - entities deleted: 0
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - entities fetched (minimize this): 0
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - collections loaded: 0
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - collections updated: 0
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - collections removed: 0
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - collections recreated: 0
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - collections fetched (minimize this): 0
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - queries executed to database: 1
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - query cache puts: 1
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - query cache hits: 1
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - query cache misses: 1
    2007-Mar-29 11:15:44 [StatisticsImpl] INFO   - max query time: 2000ms
    
    after 3rd hit
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - Logging statistics....
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - start time: 1175192124093
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - sessions opened: 3
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - sessions closed: 3
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - transactions: 1
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - successful transactions: 0
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - optimistic lock failures: 0
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - flushes: 3
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - connections obtained: 1
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - statements prepared: 1
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - statements closed: 1
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - second level cache puts: 236
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - second level cache hits: 472
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - second level cache misses: 0
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - entities loaded: 236
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - entities updated: 0
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - entities inserted: 0
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - entities deleted: 0
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - entities fetched (minimize this): 0
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - collections loaded: 0
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - collections updated: 0
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - collections removed: 0
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - collections recreated: 0
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - collections fetched (minimize this): 0
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - queries executed to database: 1
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - query cache puts: 1
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - query cache hits: 2
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - query cache misses: 1
    2007-Mar-29 11:15:47 [StatisticsImpl] INFO   - max query time: 2000ms
    
    
    after 4th hit
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - Logging statistics....
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - start time: 1175192124093
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - sessions opened: 4
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - sessions closed: 4
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - transactions: 1
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - successful transactions: 0
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - optimistic lock failures: 0
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - flushes: 4
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - connections obtained: 1
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - statements prepared: 1
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - statements closed: 1
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - second level cache puts: 236
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - second level cache hits: 708
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - second level cache misses: 0
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - entities loaded: 236
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - entities updated: 0
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - entities inserted: 0
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - entities deleted: 0
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - entities fetched (minimize this): 0
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - collections loaded: 0
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - collections updated: 0
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - collections removed: 0
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - collections recreated: 0
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - collections fetched (minimize this): 0
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - queries executed to database: 1
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - query cache puts: 1
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - query cache hits: 3
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - query cache misses: 1
    2007-Mar-29 11:15:50 [StatisticsImpl] INFO   - max query time: 2000ms

  5. #5
    Join Date
    Aug 2006
    Posts
    11

    Default

    Did some more investigating, this time I decided to take spring out of the picture but still use hibernate + ehcache + the same business object with the same mapping file. The numbers generated from the run of queries now seem to be in line to what i'm looking for for caching....

    I'm getting times of,

    ****** Get Item List exec time: 454ms -- 236 items ******
    ****** Get Item List exec time: 31ms -- 236 items ******
    ****** Get Item List exec time: 31ms -- 236 items ******
    ****** Get Item List exec time: 15ms -- 236 items ******

    The full output trace is as follows (including the statistics dump after each run)
    Code:
    starting now....
    Hibernate: /* from Country order by id */ select country0_.id as id2_, country0_.name as name2_, country0_.code as code2_, country0_.numericcode as numericc4_2_, country0_.alphacode as alphacode2_ from country country0_ order by country0_.id
    ****** Get Item List exec time:  454ms -- 236 items  ******
    - Logging statistics....
    - start time: 1175204099078
    - sessions opened: 1
    - sessions closed: 0
    - transactions: 0
    - successful transactions: 0
    - optimistic lock failures: 0
    - flushes: 0
    - connections obtained: 1
    - statements prepared: 1
    - statements closed: 1
    - second level cache puts: 236
    - second level cache hits: 0
    - second level cache misses: 0
    - entities loaded: 236
    - entities updated: 0
    - entities inserted: 0
    - entities deleted: 0
    - entities fetched (minimize this): 0
    - collections loaded: 0
    - collections updated: 0
    - collections removed: 0
    - collections recreated: 0
    - collections fetched (minimize this): 0
    - queries executed to database: 1
    - query cache puts: 1
    - query cache hits: 0
    - query cache misses: 1
    - max query time: 109ms
    starting now....
    ****** Get Item List exec time:  31ms -- 236 items  ******
    - Logging statistics....
    - start time: 1175204099078
    - sessions opened: 2
    - sessions closed: 1
    - transactions: 1
    - successful transactions: 1
    - optimistic lock failures: 0
    - flushes: 1
    - connections obtained: 2
    - statements prepared: 1
    - statements closed: 1
    - second level cache puts: 236
    - second level cache hits: 236
    - second level cache misses: 0
    - entities loaded: 236
    - entities updated: 0
    - entities inserted: 0
    - entities deleted: 0
    - entities fetched (minimize this): 0
    - collections loaded: 0
    - collections updated: 0
    - collections removed: 0
    - collections recreated: 0
    - collections fetched (minimize this): 0
    - queries executed to database: 1
    - query cache puts: 1
    - query cache hits: 1
    - query cache misses: 1
    - max query time: 109ms
    starting now....
    ****** Get Item List exec time:  31ms -- 236 items  ******
    - Logging statistics....
    - start time: 1175204099078
    - sessions opened: 3
    - sessions closed: 2
    - transactions: 2
    - successful transactions: 2
    - optimistic lock failures: 0
    - flushes: 2
    - connections obtained: 3
    - statements prepared: 1
    - statements closed: 1
    - second level cache puts: 236
    - second level cache hits: 472
    - second level cache misses: 0
    - entities loaded: 236
    - entities updated: 0
    - entities inserted: 0
    - entities deleted: 0
    - entities fetched (minimize this): 0
    - collections loaded: 0
    - collections updated: 0
    - collections removed: 0
    - collections recreated: 0
    - collections fetched (minimize this): 0
    - queries executed to database: 1
    - query cache puts: 1
    - query cache hits: 2
    - query cache misses: 1
    - max query time: 109ms
    The code i wrote to run this was simple enough ... it was as follows. Now this brings a few more questions. Why would the performance numbers when spring is involved be such a big difference? Am i suppose to use the getHibernateTemplate() method to execute my queries? or should i be doing something else?

    Code:
        public static void executeTest()
        {
            Transaction tx = null;
            
            try
            {                        
                SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
                
                Session session = sessionFactory.openSession();
    
                List resultList;
    
                System.out.println("starting now....");
                long startTime = System.currentTimeMillis();
                
                tx = session.getTransaction();
                tx.begin();    
                            
                Query query = session.createQuery("from Country order by id").setCacheable(true);
                
                resultList = query.list();
                long endTime = System.currentTimeMillis();            
                System.out.println("****** Get Item List exec time:  " + (endTime - startTime) + "ms -- " + resultList.size() + " items  ******" );
                sessionFactory.getStatistics().logSummary();
                
                tx.commit();     
                session.close();
                
            }
            catch (RuntimeException e)
            {
                if (tx != null)
                {
                    tx.rollback();
                }
                e.printStackTrace();
            }    
        }

  6. #6

    Default

    very interesting, i wish i could offer some insight into this

    how do you get the stats to show up like that? i need to do this myself so i can verify that everything is in fact working as it should

  7. #7
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Looking at the code.
    Code:
    sessionFactory.getStatistics().logSummary();

  8. #8
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    56

    Default

    Quote Originally Posted by Flyboy604 View Post
    It appears the countries are loaded into cache, and it appears that the DAO is doing a hit on the cache to load the objects. So it seems all working, however i still don't see how the exectuion time can not change for the DAO call.
    Actually, looking at the stats you've provided you have zero cache hits for both 2nd level cache and query cache. There's something wrong with your cache config or Hibernate initialization sequence.

    BTW, are you using Spring factory beans for initializing EHCache?

  9. #9
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    If you have a read of the reference documentation I posted earlier, it talks about the query cache. Although you have configured caching for individual objects, I think you also need to add either a general or some specific query caches. Have a look at the links.

    e.g.
    StandardQueryCache
    This cache is used if you use a query cache without setting a name. A typical ehcache.xml configuration is:
    Code:
    <cache
        name="org.hibernate.cache.StandardQueryCache"
        maxElementsInMemory="5"
        eternal="false"
        timeToLiveSeconds="120"
        overflowToDisk="true"/>

  10. #10
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    You don't seem to have a cache entry in your .hbm.xml file.

    Code:
    <hibernate-mapping> 
        <class name="com.gdi.core.businessobjects.Country" table="country"> 
    
        <cache usage="read-write"/>
    
        ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •