File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate cache issues

 
andy kumar
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a very strange issue with hibernate ehcache. Below is my scenario:-

I have a function that updates a table in the db and sends the rowid as a message to a MQ queue. I am using distributed transaction here. The the listener gets the rowid and then retrieves the record from the DB, here is where the issues is. With ehcache disabled all is fine but on enabling ehcache when the listener tries to get the record it is getting stale data. I am using Spring Hibernate template




When I use the above listner code I get stale data, but if I replace the code by a named query it works fine so the below code works:-

List<Booking> results = getHibernateTemplate().findByNamedQuery(
"Booking.getBookingByBookingSeqId", bookingSeqId);

I am unable to understand why this is happening......I also tried to purge the cache when working with ehcache enabled but that also did not work. I was basically calling it as below

My main question is why does the get() method return me stale data and a named query works when ehcache is enable, and why is the purgecache not working.....

Any help will be greatly appreciated....though things work for me now as i am using named query but I really don't understand what I am doing wrong.

thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Queries are only cached if you are using a Query cache and a cacheable query.

Do you have a cache region called "modelName like com.anuj.test"? Seems like an odd name to use.
 
andy kumar
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The query cache is set to true:-

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.default_schema">${hibernate.default_schema}</prop>
<prop
key="hibernate.transaction.manager_lookup_class">
org.hibernate.transaction.WebSphereTransactionManagerLookup
</prop>
<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop>
<prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
<prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
<prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
<prop key="net.sf.ehcache.configurationResourceName">${ehcache.config.location}</prop>
</props>


Oh i am actually giving the model object name there (com.anuj.test.java is the actual model object) , not the cache region name that may be the issue. But why is named query working as opposed to the get() method.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my previous answer.
 
andy kumar
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Paul got it....
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic