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

Hibernate caching- Which caching to use for performance ?

 
amit attri
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate 2nd level cache.
 
amit attri
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic