• 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]: Second Lv Cache (with Async Updates)

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ranchers,

I have this peculiar requirement to cache objects in an application.
These objects cached are data mainly used for gui-construction.
The problem here is that these data can be updated by the same application, but the changes in the database should not effect till the user forces a refresh on the cache.

Currently, I've tried to do this using two HibernateUtils with two sessionfactories (reading from different hibernate.cfg.xml but using same entities). For the hbms in my HibernateUtils2, i've declared the entity to be read-only.

However, when I updated the object from SessionFactory1, the object cached in SessionFactory2 is also being updated.

The way I can do what I want now is by using 2 separate process.


Any idea, where i've gone wrong? (sorry i'm kinda new to all these orm and especially caching)

Thanks in advance.

Regards
Terry.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rather strange requirement. Are you having cache definitions in both the configuration files ? And are you sure the cache is being hit when using SessionFactory2 and not the database?
 
Terry Ong
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Rather strange requirement.

Yes, I agree.

> Are you having cache definitions in both the configuration files ?

Yes for both of them

[hibernate1.cfg]
GuiData entity -> GUI_TABLE Tablename
CacheGuiData entity -> GUI_TABLE Tablename

[hibernate2.cfg]
CacheGuiData entity -> GUI_TABLE Tablename


> And are you sure the cache is being hit when using SessionFactory2
> and not the database?


I've turn on the statistics for 2nd level cache using the follow code;
and there is some hits:
long hits = sf.getStatistics().getSecondLevelCacheHitCount();

is this correct?
 
Terry Ong
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think I found the error.
I declared the same ehcache config for both hibernate.cfg.xml.
Somehow due to this the entities get interference from each other.


Thanks for the tip, Lakshmi.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic