aspose file tools*
The moose likes Object Relational Mapping and the fly likes [Hibernate]: Second Lv Cache (with Async Updates) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "[Hibernate]: Second Lv Cache (with Async Updates)" Watch "[Hibernate]: Second Lv Cache (with Async Updates)" New topic
Author

[Hibernate]: Second Lv Cache (with Async Updates)

Terry Ong
Ranch Hand

Joined: Apr 07, 2006
Posts: 50
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.
Lakshmi Dasari
Ranch Hand

Joined: Mar 03, 2003
Posts: 35
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?


Lakshmi
Terry Ong
Ranch Hand

Joined: Apr 07, 2006
Posts: 50
> 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

Joined: Apr 07, 2006
Posts: 50
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Hibernate]: Second Lv Cache (with Async Updates)