• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

The hibernate query cache only seems to work for some queries. What are the criteria for which queries are or are not cached?

The hibernate query cache only seems to work for some queries. What are the criteria for which queries are or are not cached?

When I call
query.setCacheable(true);
after a query, sometimes the query gets cached and sometimes it does not.

See the sql below to see a few of the queries that are not being cached.

Hibernate version:
3.0.2

The generated SQL (show_sql=true):
Hibernate: select fieldstrin0_.cobj as cobj__, fieldstrin0_.id as id__, fieldstrin0_.id as id0_, fieldstrin0_.val as val11_0_, fieldstrin0_.cobj as cobj11_0_, fieldstrin0_.meta as meta11_0_ from know.customobjfieldstringsearch fieldstrin0_ where fieldstrin0_.cobj=?
Hibernate: select objtype0_.id as col_0_0_ from know.objtype objtype0_ where objtype0_.visibility in (?) order by objtype0_.capitalizedSingularName
Hibernate: select this_.id as id0_, this_.visibility as visibility28_0_, this_.modStatus as modStatus28_0_, this_.whenCreated as whenCrea4_28_0_, this_.unumCreated as unumCrea5_28_0_, this_.whenModified as whenModi6_28_0_, this_.unumModified as unumModi7_28_0_, this_.capitalizedPluralName as capitali8_28_0_, this_.longDesc as longDesc28_0_, this_.isSuperset as isSuperset28_0_, this_.parent as parent28_0_, this_.capitalizedSingularName as capital12_28_0_ from know.objtype this_ order by this_.capitalizedPluralName asc
Hibernate: select this_.id as id0_, this_.visibility as visibility26_0_, this_.modStatus as modStatus26_0_, this_.whenCreated as whenCrea4_26_0_, this_.unumCreated as unumCrea5_26_0_, this_.whenModified as whenModi6_26_0_, this_.unumModified as unumModi7_26_0_, this_.longDesc as longDesc26_0_, this_.isSuperset as isSuperset26_0_, this_.capitalizedSingularName as capital10_26_0_ from know.listtype this_ order by this_.capitalizedSingularName asc
Hibernate: select this_.id as id0_, this_.listType as listType25_0_, this_.objType as objType25_0_ from know.listtypeallowed this_
0
HappyEngineer
Asked:
HappyEngineer
1 Solution
 
aozarovCommented:
I assume you call query.setCacheable(true); before you execute hat specific query.

>> What are the criteria for which queries are or are not cached?
The documentation mention nothing about it (lets you assume that it is only depends on your settings). see: http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#performance-cache
You can always look at the source code of Query.

>>after a query, sometimes the query gets cached and sometimes it does not.
Do you mean never? When a query was cached it will not be cached again if the data behind it wasn't changed.

>>See the sql below to see a few of the queries that are not being cached.
So you say that those are never cached even when settings their query.setCachable to true?
Are the tables involved with those queries are set to be cachables?
You can submit this question to the Hibernate forum: http://forum.hibernate.org/ (Oops, just realized that you actually did that mxnmatch ;-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now