[hibernate-issues] [Hibernate-JIRA] Created: (HHH-6568) QueryStatistics's getExecutionMinTime() return Long.MAX_VALUE instead of zero when execution count is zero and cache hit is greater than zero

Julien Kronegg (JIRA) noreply at atlassian.com
Fri Aug 12 10:57:05 EDT 2011


QueryStatistics's getExecutionMinTime() return Long.MAX_VALUE instead of zero when execution count is zero and cache hit is greater than zero
---------------------------------------------------------------------------------------------------------------------------------------------

                 Key: HHH-6568
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6568
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 4.0.0.Beta5, 3.6.6, 3.3.1
         Environment: Hibernate (at least 4.0.0 Beta5, 3.6.6, 3.3.1), EhCache 2.4.3, JGroups 2.12.1, DB2
            Reporter: Julien Kronegg
            Priority: Minor


h3. Introduction / Summary
QueryStatistics initializes the {{executionMinTime}} field to {{Long.MAX_VALUE}}. When the execution count is zero, this causes {{getExecutionMinTime()}} to return {{Long.MAX_VALUE}} instead of an expected value of 0 because the initial value has not yet been updated but a cache hit has already been done.

h3.Test case
This can occur with two applications based on Hibernate and having its EhCache synchronized in replication mode (e.g. using JGroups): the first application does a query with query cache enabled (generates a miss, an execution and a put in the query statistics), then second application query cache is synchronized by replication of the query result (an implicit put without updating the second application query statistics). Finally, the second application does the same query (this generates a hit, but no execution): getting the minimum execution time will return {{Long.MAX_VALUE}}. 

h3. Location in the source code
The issue occurs in the new [Hibernate 4 Beta's ConcurrentQueryStatisticsImpl|https://github.com/hibernate/hibernate-core/blob/master/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentQueryStatisticsImpl.java] as well as in current [Hibernate 3.6's QueryStatisticsImpl|https://github.com/hibernate/hibernate-core/blob/3.6/hibernate-core/src/main/java/org/hibernate/stat/QueryStatisticsImpl.java] and in older versions, e.g. [Hibernate 3.3's QueryStatistics|https://github.com/hibernate/hibernate-core/blob/3.3/core/src/main/java/org/hibernate/stat/QueryStatistics.java].

h3. Solution
To be corrected, {{getExecutionMinTime}} should be corrected to return the executionMinTime only if the execution count is greater than zero, otherwise it should return zero. For example in Hibernate 3.6:
{code}
public long getExecutionMinTime() {
  return executionMinTime;
}
{code}
should be replaced by
{code}
public long getExecutionMinTime() {
  return (executionCount>0?executionMinTime:0);
}
{code}
Also the {{toString()}} method should call the {{getExecutionMinTime()}} method instead of using the underlying {{executionMinTime}} field.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list