Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Session Cache for load and query cache ?

 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Difference between Session Cache for load and query cache ?

Why session cache doesn't work for Query query = session.createQuery() ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I'm not understanding you. Is that a question?
 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic