This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Difference between Session Cache for load and query cache ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Difference between Session Cache for load and query cache ?" Watch "Difference between Session Cache for load and query cache ?" New topic
Author

Difference between Session Cache for load and query cache ?

Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
Hi,

Difference between Session Cache for load and query cache ?

Why session cache doesn't work for Query query = session.createQuery() ?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The session cache is a cache of objects loaded over the course of a session. So any calls to session.get or session.load will use this. The query cache is a cache of queries and identifiers of results, the objects themselves have not been loading into the session so are not cached. It makes no sense to use a query cache unless you also use a second level cache.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
Means we are loading the Object itself while using get() or load() nethod, While Result set of Query using select clause doesn't load the actual objects.

and yes Query is used for second Level cache only,

This example does make sence:




Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Sorry, I'm not understanding you. Is that a question?
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
I am saying this way we can achieve 2nd Level Query cache.Session is related to load the actual Object as Session is transaction-level cache.

My question is ,
1) Query cache --> retrives the ResultSet of the Query requested to database , its Loading into the cache the P.K of that record of result set.

2) If we don't use this setting:

query.setCacheable(true);

then how hibernate will treat for this , as default query cache is not enabled ?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not sure what Hibernate will do, but my guess is ignore the cacheable attribute of the query. Easy enough to test and see I suppose.

Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
ok Let me put this question.

suppose we have used cache query and it is 2nd level Hibernate Cache , how long it will be available till the sessionFactory lives ?

or can we refresh or close or unload the cache result set.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between Session Cache for load and query cache ?
 
Similar Threads
sql query cache Vs Object level cache
Sessions in Hibernate
clustering and load balancing
Session Facade vs Session Bean
Caching Database resultset