diff --git a/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentStatisticsImpl.java b/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentStatisticsImpl.java index e8032fd090..f16dc1afa6 100644 --- a/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentStatisticsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentStatisticsImpl.java @@ -187,6 +187,7 @@ public class ConcurrentStatisticsImpl implements StatisticsImplementor, Service entityStatistics.clear(); collectionStatistics.clear(); queryStatistics.clear(); + naturalIdCacheStatistics.clear(); startTime = System.currentTimeMillis(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/naturalid/mutable/cached/CachedMutableNaturalIdStrictReadWriteTest.java b/hibernate-core/src/test/java/org/hibernate/test/naturalid/mutable/cached/CachedMutableNaturalIdStrictReadWriteTest.java index 82e7c49c24..404e999fc6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/naturalid/mutable/cached/CachedMutableNaturalIdStrictReadWriteTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/naturalid/mutable/cached/CachedMutableNaturalIdStrictReadWriteTest.java @@ -1,15 +1,18 @@ package org.hibernate.test.naturalid.mutable.cached; +import org.hibernate.Session; +import org.hibernate.cfg.Configuration; +import org.hibernate.stat.NaturalIdCacheStatistics; + +import org.junit.Test; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.cache.CachingRegionFactory; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import org.hibernate.Session; -import org.hibernate.cfg.Configuration; -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.cache.CachingRegionFactory; -import org.junit.Test; - public class CachedMutableNaturalIdStrictReadWriteTest extends CachedMutableNaturalIdTest { @@ -151,4 +154,27 @@ public class CachedMutableNaturalIdStrictReadWriteTest extends session.getTransaction().commit(); assertEquals("In a strict access strategy we would excpect a hit here", 1, session.getSessionFactory().getStatistics().getNaturalIdCacheHitCount()); } + + @Test + @TestForIssue( jiraKey = "HHH-9200" ) + public void testNaturalIdCacheStatisticsReset() { + final String naturalIdCacheRegion = "hibernate.test.org.hibernate.test.naturalid.mutable.cached.Another##NaturalId"; + sessionFactory().getStatistics().clear(); + + final Session session = openSession(); + session.beginTransaction(); + final Another it = new Another( "IT"); + session.save( it ); + session.getTransaction().commit(); + session.close(); + + NaturalIdCacheStatistics statistics = sessionFactory().getStatistics().getNaturalIdCacheStatistics( naturalIdCacheRegion ); + assertEquals( 1, statistics.getPutCount() ); + + sessionFactory().getStatistics().clear(); + + // Refresh statistics reference. + statistics = sessionFactory().getStatistics().getNaturalIdCacheStatistics( naturalIdCacheRegion ); + assertEquals( 0, statistics.getPutCount() ); + } }