Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Caching not clear

 
Poornima Sharma
Ranch Hand
Posts: 114
  • 0
  • 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,
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic