-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate cache
PostPosted: Mon Mar 27, 2006 12:56 pm 
Newbie

Joined: Mon Mar 27, 2006 12:35 pm
Posts: 4
Hi

I am trying to understand the second level cache behaviour. I see that we can cache classes and collections ( apart from query caching).

I am trying to understand how a class cache works. If let us say I have a table User and I am going to build a query using 'firstName' - unless I use query cache, requests are going to go to database irrespective of if the user objects are cached in cache. Isn't that correct? If yes, then the only scenario in which the cached user objects would be used is when another object has a reference to the cached user object. Is my understanding correct?


I tried enabling collection cache and noticed that unless I have the corresponding destination class cache entry enabled for caching explicitly using class-cache, the collections weren't being cached. Is that valid?

Appreciate any response.

Thanks
Sreeram


Top
 Profile  
 
 Post subject: Re: Hibernate cache
PostPosted: Mon Mar 27, 2006 1:23 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
Your understanding is correct, yet:
sreeram.katta wrote:
...If yes, then the only scenario in which the cached user objects would be used is when another object has a reference to the cached user object.


If you query the objects, the "query" and it's results elements by ID are cached in the Query Cache, and they would also have the "values" in the 2nd level cache too. To utilize the cached objects at this point, you need to use the "same" query again, or get or load, or navigate to the object (basically access the object by ID).

l2 Cache is basically a hashmap by ID of items. and Collections are similar, in that the "collection" is cached with ID's. If you want to Query cached objects by item's VALUEs, then you'll need to use the Query Cache.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 11:10 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
If I'm not mistaken you can also cache by natural identifier. See the Hibernate docs. They suggest that if you include natural id elements in your mapping, that these queries to will become cacheable.

So, there is an alternative to surrogate-key only caching.

Cheers,
Roll

Please rate if you thought this helped.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.