This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Performance and the fly likes Hibernate caching- Which caching to use for performance ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Hibernate caching- Which caching to use for performance ?" Watch "Hibernate caching- Which caching to use for performance ?" New topic
Author

Hibernate caching- Which caching to use for performance ?

amit attri
Greenhorn

Joined: Aug 24, 2011
Posts: 8
Hi All,

I'm working on java application, that runs in tomcat and uses hibernate orm to query oracle database.

There are many tables in which data is rarely changed. These data are only changed by a third party application. (Not the one on which I'm working).

I need to put these tables' data in cache. Which is the best cache to use ?
(Please don't recomend query cache as it has timestamp lock as its problem).

Help !!!
Rishi Shehrawat
Ranch Hand

Joined: Aug 11, 2010
Posts: 218

Hibernate 2nd level cache.
amit attri
Greenhorn

Joined: Aug 24, 2011
Posts: 8
Thanks for your reply !!! But I there will be certain third party application that will be changing data (that i will put in second level cache). Will cache be able to invalidate data as data changes. I'm working on application that deals with money. Hence data is very critical.
Rishi Shehrawat
Ranch Hand

Joined: Aug 11, 2010
Posts: 218

The cache will not be able to detect changes made directly to the database. In case you are able to intercept/detect changes made by third party application you can invalidate the cache, however i think that this will not be easy as third party will be updating the database directly using JDBC.
amit attri
Greenhorn

Joined: Aug 24, 2011
Posts: 8
Q1 The third party application is updating data using Hibernate only. I can even modify code in third party app.
Can both cahe (of third party and my app) synchronize their data ? If yes, How can I do that ?

Q2 In case I use second level cache as you suggested.... I read about it that it makes very frequent invalidation. And also if data of one table is changed, then entire cache is refreshed. Is it true ?

Rishi Shehrawat
Ranch Hand

Joined: Aug 11, 2010
Posts: 218

Q1 The third party application is updating data using Hibernate only. I can even modify code in third party app.
Can both cahe (of third party and my app) synchronize their data ? If yes, How can I do that ?

You can invoke method on cache to invalidate when external system updates data. The cache can expose a method for this via JMX.

Q2 In case I use second level cache as you suggested.... I read about it that it makes very frequent invalidation. And also if data of one table is changed, then entire cache is refreshed. Is it true ?

You have control over what part of cache you want to invalidate & the frequency of invalidation. Please refer to documentation provided by cache provider that you are planning to use.
amit attri
Greenhorn

Joined: Aug 24, 2011
Posts: 8
I'm super naive in JMX.
Can you provide me a detailed documentation (beginner) to use JMX in case of multiple tomcat servers updating single oracle database server ? Is hibernate involved in this ?
Mudit Srivastava
Ranch Hand

Joined: Apr 30, 2007
Posts: 38
amit attri wrote:Q1 The third party application is updating data using Hibernate only. I can even modify code in third party app.
Can both cahe (of third party and my app) synchronize their data ? If yes, How can I do that ?



You could configure your second level cache as "read - write". If the request is going via hibernate itself, the cache should synchronize the changes automatically.

Read-Write Details

However by relying on cached entities, you risk having an out-of-sync cache when an update happens in the database via a different request, so ensure all requests go via hibernate itself.

amit attri wrote:Q2 In case I use second level cache as you suggested.... I read about it that it makes very frequent invalidation. And also if data of one table is changed, then entire cache is refreshed. Is it true ?



force eh cache
 
Don't get me started about those stupid light bulbs.
 
subject: Hibernate caching- Which caching to use for performance ?