This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Hibernate cache issues  RSS feed

 
Ranch Hand
Posts: 64
  • 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
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my previous answer.
 
andy kumar
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Paul got it....
 
today's feeble attempt to support the empire
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!