-->
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.  [ 3 posts ] 
Author Message
 Post subject: General question about caching.
PostPosted: Fri May 15, 2009 2:59 pm 
Beginner
Beginner

Joined: Fri Dec 10, 2004 11:46 pm
Posts: 37
I have caching working. I have some question based on my understanding of what I think should be happening.

My config case...

Code:

hibernate.cfg.xml
<property name="cache.use_query_cache">true</property>
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>   
<property name="net.sf.ehcache.configurationResourceName">ehcache.xml</property>

ehcache.xml
<cache name="com.my.com.Cat"
   maxElementsInMemory="20" eternal="false" timeToIdleSeconds="120"
   timeToLiveSeconds="180" overflowToDisk="false" />

Cat.hbm.xml
<class name="com.my.com.Cat" table="`CATS`"
      dynamic-insert="true" dynamic-update="true">

      <cache usage="read-write" />
...
</class>


Code:
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();

The JAVA code
Cat c;
c = cDAO.findById(1, false); // <-- Dao as described in hibernate wiki and docs. Uses load()

HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();



The above code runs in a web service stress tested by SOAP UI. You would think that after the first call to the web service that there would be no activity on the Db but there is. What is going on exactly?


Top
 Profile  
 
 Post subject: Re: General question about caching.
PostPosted: Tue May 19, 2009 3:34 pm 
Newbie

Joined: Sat Nov 29, 2008 10:56 am
Posts: 8
You should enable statistics and view the cache statistics to see if the entity is being cached. You can also turn on the logger for the cache class to see if it is rejecting the attempt to cache the object. If I was a betting man then I would think that your object is being rejected for caching.


Top
 Profile  
 
 Post subject: Re: General question about caching.
PostPosted: Tue May 19, 2009 4:43 pm 
Beginner
Beginner

Joined: Fri Dec 10, 2004 11:46 pm
Posts: 37
Caching is working fine. I enabled stats cache was being hit 100% no misses. So I then fired up SQL profiler.

The extra activity is all the SET TRANSACTION, COMMIT TRANSACTION calls, there no actual call to SELECT. Kind of redundant, but I guess Hibernate cannot exactly guess if it's all cache or not especially in far more complex applications.


My code is simple

begin trx
read cat
commit trx

One thing I noticed is if make 1 request and then a subsequent request

I get 1 put, 1 hit. Which is right and then when I run SOAP UI I it stays at 1 puts and x hits (Correct)
But if I test from SOAP UI directly without an initial request I sometimes get 100 puts x hits...


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