• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Caching not clear

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic