• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Hibernate Caching not clear  RSS feed

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I am using EHCache in hibernate and I have to implement readonly cache for all the master data tables. To implement it i made the following changes in hbm files:-



In my above code, the data of COMPANY Table is static, however the data in EMPLOYEE table gets updated, so I have to remove the second cache entry inside list from the above code. But im not sure, will i always fetch the updated data of EMPLOYEE when i fetch the data of COMPANY.

What is the process of caching? How does caching works with classes and collections?

Please guide.

Thanks,
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have initialized the collection it will be in the cache, and you will have initialized it if you have accessed any property of the collection. Because this is a read only cache that data will not be refreshed in the cache if you update the employee from Hibernate. You could make the employee object not participate in the cache read-write (if that is appropriate).
 
Poornima Sharma
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Sturrock wrote:You could make the employee object not participate in the cache read-write (if that is appropriate).



Yes, I don't want the employee object participate in the cache read or write. To implement this I have removed "<cache usage="read-only"/>" code from the list of Company hbm mapping file. Is that sufficient or do i need to remove the all the cache entires from the COMPANY hbm file?

Please guide.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that should be enough (assuming your entity is configured with the non-lazy cache attribute). Hibernate should now refresh the collection from the database when you access it in a new session, regardless of the state of the company record in the second level cache.
 
Poornima Sharma
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. It means that my master table will always fetch the collection data from the database if I have not explicitly cached the collection.
 
Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!