-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Need Help with Caching in Hibernate in Clustered Environment
PostPosted: Thu Jan 04, 2007 3:42 pm 
Newbie

Joined: Thu Jan 04, 2007 3:34 pm
Posts: 2
Hibernate version: 3.0
Name and version of the database you are using: MySQL 5.0

Hi,

I want to run my application in a clustered environment, and was wondering how Hibernate cache will behave in this case.

Suppose there are two application servers A and B. If Hibernate puts some data in its cache on server A, and the same data is modified using server B, then how will Hibernate know of this change in Server A ? This way application can serve stale content.

Is there a way to avoid the above problem without loosing much performance ?

Thanks in Advance
Varun


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 4:31 pm 
Newbie

Joined: Mon Jul 24, 2006 1:35 pm
Posts: 10
Hi,

I think that data stored in Hibernate session is only visible within same VM by default. If you want to have shared cache, you'll need to get something like Tangosol Coherence and configure Hibernate to use that. Otherwise data loaded into session in cluster A will be separate from data loaded into session in cluster B.
If you need to somehow restrict access to given rows in db you could use lock for update (in Hibernate session). Or get a distributed cache product like Tangosol.

HTH,

Bratek


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 8:04 pm 
Newbie

Joined: Wed Aug 03, 2005 2:13 am
Posts: 16
Both ehcache and JBoss TreeCache are clusterable. You just need to use one of them as your second-level cache provider in Hibernate, and configure them properly for your cluster. You don't need Tangosol.

http://www.hibernate.org/hib_docs/v3/reference/en/html/performance.html#performance-cache

Note that link does not list ehcache as being cluster-safe, but it has had this capability for awhile now and is considered stable - http://ehcache.sourceforge.net/

Note that I am talking about the Hibernate's second-level cache here, not a given Hibernate Session, which is what bratek seemed to refer to. But I think this is what you are after.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 05, 2007 5:56 am 
Newbie

Joined: Fri Jan 05, 2007 5:50 am
Posts: 1
Location: San Francisco, CA
You might also want to look at our GigaSpaces - Hibernate plug-in.

More info here: http://www.gigaspaces.com/wiki/display/ ... che+Plugin

And here: http://hibernate.org/201.html.

_________________
Geva Perry
Blog: http//gevaperry.typepad.com


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 07, 2007 3:00 am 
Newbie

Joined: Thu Jan 04, 2007 3:34 pm
Posts: 2
I think using Tangosol, ehcache or gigaspaces will solve the problem of second-level cache in a clustered environment. But, I also have one more problem.

I have a second application which can modify the same datastore as the second application. Both uses Hibernate's second-level cache. How to synchronise cache in this case ? Do, I have to write my own CacheProvider to handle this ? If yes, then can somebody point a good reference to do so.

Thanks in Advance
Varun


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 08, 2007 1:02 am 
Newbie

Joined: Tue Dec 12, 2006 9:07 am
Posts: 13
Iam not very sure if it will work, but if both your applications are using "Hibernate" and the "same second-level caching" mechanism to access the datastore, then you could configure your cache to sync all the clustered caches through the configuration file. Jbosscache is a good clustered cache option too.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.