[hibernate-issues] [Hibernate-JIRA] Issue Comment Edited: (HHH-5870) Cache invalidation bug: createSQLQuery(String sql) creates SQLQueryImpl with null querySpaces, making UpdateTimestampsCache:isUpToDate always return true
nodje (JIRA)
noreply at atlassian.com
Thu Jan 27 06:11:05 EST 2011
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5870?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39767#action_39767 ]
nodje edited comment on HHH-5870 at 1/27/11 5:09 AM:
-----------------------------------------------------
I can't quickly post a test case. It is rather difficult to build one. Webapp boiler plate code + database + mapping + test case ...
I hope just listing the code that is processed in the scenario can make sense for someone familiar with it:
Imagine the following code: SQLQuery query = session.createSQLQuery("sqlQueryString").setCacheable(true);
Session:730
SessionImpl:1776
AbstractSessionImpl:146 new SQLQueryImpl
SQLQueryImpl:138 <--- this is were the problem originate from: querySpaces = null (SQLQueryImpl:141).
They'll never be any space added. The only way to add some seems to be SQLQueryImpl:366 addSynchronizedQuerySpace(...) - undocumented
Then call a query.list();
SQLQueryImpl:149
SessionImplementor:221
AbstractSessionImpl:165
SessionImplementor:204
SessionImpl:1835 CustomLoader loader is instanciated with quesySpaces from the customQuery: null
SessionImpl:1842 loader.list
CustomLoader:316 querySpace is still null here
Loader:2268 since it's cacheable
Loader:2309 getResultFromQueryCache since the query result is already in cache - the bug is that it won't invalidate the cached result
Loader:2561 queryCache.get
QueryCache:48
StandardQueryCache:135 <-- if ( !isNaturalKeyLookup && !isUpToDate( spaces, timestamp ) ) lead to isUpToDate with spaces being empty
StandardQueryCache:185 <-- updateTimestampsCache.isUpToDate( spaces, timestamp );
UpdateTimestampsCache:89 : public synchronized boolean isUpToDate(Set spaces, Long timestamp) throws HibernateException
Set spaces is empty, isUpToDate returns true
the queryCache.get returns the cached result.
HTH
was (Author: nodje):
I can't quickly post a test case. It is rather difficult to build one. Webapp boiler plate code + database + mapping + test case ...
I hope just listing the code that is processed in the scenario can make sense for someone familiar with it:
Imagine the following code: SQLQuery query = session.createSQLQuery("sqlQueryString").setCacheable(true);
Session:730
SessionImpl:1776
AbstractSessionImpl:146 new SQLQueryImpl
SQLQueryImpl:138 <--- this is were the problem originate from: querySpaces = null (SQLQueryImpl:141).
They'll never be any space added. The only way to add some seems to be SQLQueryImpl:366 addSynchronizedQuerySpace(...) - undocumented
Then call a query.list();
SQLQueryImpl:149
SessionImplementor:221
AbstractSessionImpl:165
SessionImplementor:204
SessionImpl:1835 CustomLoader loader is instanciated with quesySpaces from the customQuery: null
SessionImpl:1842 loader.list
CustomLoader:316 querySpace is still null here
Loader:2268 since it's cacheable
Loader:2309 getResultFromQueryCache since the query result is already in cache - the bug is that it won't invalide the cached result
Loader:2561 queryCache.get
QueryCache:48
StandardQueryCache:135 <-- if ( !isNaturalKeyLookup && !isUpToDate( spaces, timestamp ) ) lead to isUpToDate with spaces being empty
StandardQueryCache:185 <-- updateTimestampsCache.isUpToDate( spaces, timestamp );
UpdateTimestampsCache:89 : public synchronized boolean isUpToDate(Set spaces, Long timestamp) throws HibernateException
Set spaces is empty, isUpToDate returns true
the queryCache.get returns the cached result.
HTH
> Cache invalidation bug: createSQLQuery(String sql) creates SQLQueryImpl with null querySpaces, making UpdateTimestampsCache:isUpToDate always return true
> ---------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: HHH-5870
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5870
> Project: Hibernate Core
> Issue Type: Bug
> Components: caching (L2)
> Affects Versions: 3.6.0
> Environment: OS X 10.6.6 - Java 1.6.0_22
> Reporter: nodje
> Priority: Blocker
>
> While investigating a regression seemingly caused by cache problem on an application, I stumbled upon
> UpdateTimestampsCache:89 method public synchronized boolean isUpToDate(Set spaces, Long timestamp) throws HibernateException
> always returning true when parameter spaces Set empty.
> This is the cause of my regression: QueryCache gets hit even though returned entities have been updated after the query fired first time.
> While trying to understand what caused Set spaces to be empty - which to me is the cause of the error - I realized it is just created like that in SQLQueryImpl:138.
> SQLQueryImpl(String sql, SessionImplementor session, ParameterMetadata parameterMetadata) {
> super( sql, null, session, parameterMetadata );
> queryReturns = new ArrayList<NativeSQLQueryReturn>();
> querySpaces = null;
> callable = false;
> }
> While there's probably a way to specify querySpaces (I can only trace it to using addSynchronizedQuerySpace in SQLQuery - which is not referenced in the doc), I believe everybody expect a default behavior, i-e a default querySpace to work with, so that isUpToDate check can work properly.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list