File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes A question with cache attribute usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "A question with cache attribute usage " Watch "A question with cache attribute usage " New topic

A question with cache attribute usage

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi All ,

I am trying to clear some doubts with Hibernate for getting a Job ASAP . so please help me .

If one configures Ehcache as second level cache with Hibernate and uses a READ_WRITE strategy as say <cache usage="read-write"/>

"Then my understanding with respect to above is that " Whenever there is a change of the entity at the database level the cache is also updated simultaneously " please tell me if i am right or wrong on this .

Waiting for your replies

Save India From Corruption - Anna Hazare.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Anybody please help
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

If someone underwrites the data in the database, and your Hibernate Session doesn't have a lock on that data, I can't see how Hibernate could update that second level cache. It's not really just a deficiency in Hibernate. It's just a matter of controlling how many different fingers are in the database pie.

-Cameron McKenzie
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi Cameron ,

You had mentioned a great point in using the risk of read - write cache . So please tell me how can i lock the resources when working with read-write cache ?

Do i need to problematically lock the resources or the Hibernate Framework manages this ?
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Pessimistic locking of resources in a database backed application is almost always a bad idea. It turns a resource designed to support concurrent access to one that only supports serial access. You would normally use an optimistic locking mechanism to check before update if things have changed (to prevent lost updates) and in the case of a second level cache you would also carefully choose the data you allow in this cache, since frequently updated data is not a good candidate for a cache.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Good point Paul . Thank you .
subject: A question with cache attribute usage
Similar Threads
Hibernate caching- Which caching to use for performance ?
Hibernate caching issue
How to get List of objects from Second Level Cache
Where to Cache associations/sets/collections
cache usage = "read-only "