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.
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.
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:
should be replaced by
Also the toString() method should call the getExecutionMinTime() method instead of using the underlying executionMinTime field.
Hibernate (at least 4.0.0 Beta5, 3.6.6, 3.3.1), EhCache 2.4.3, JGroups 2.12.1, DB2
This is a regression introduced in
This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.
For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/
As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.
The corrresponding class in 5.0 org.hibernate.stat,internal.ConcurrentStatisticsImpl does not implement a method to return the minimum execution time (e.g. no getQueryExecutionMaxTime). Thus, version 5 is not impacted by this issue.
Thanks for verifying Julien!