use of org.hibernate.stat.spi.StatisticsImplementor in project hibernate-orm by hibernate.
the class CachingWithSecondaryTablesTests method testUnstrictUnversioned.
@Test
public void testUnstrictUnversioned() {
sessionFactory = buildSessionFactory(Person.class, false);
final StatisticsImplementor statistics = sessionFactory.getStatistics();
inTransaction(sessionFactory, s -> s.persist(new Person("1", "John Doe", true)));
// it should not be in the cache because it should be invalidated instead
assertEquals(statistics.getSecondLevelCachePutCount(), 0);
assertFalse(sessionFactory.getCache().contains(Person.class, "1"));
inTransaction(sessionFactory, s -> {
statistics.clear();
final Person person = s.get(Person.class, "1");
assertTrue(Hibernate.isInitialized(person));
assertThat(statistics.getSecondLevelCacheHitCount(), CoreMatchers.is(0L));
statistics.clear();
});
}
use of org.hibernate.stat.spi.StatisticsImplementor in project hibernate-orm by hibernate.
the class CachingWithSecondaryTablesTests method testStrictUnversioned.
@Test
public void testStrictUnversioned() {
sessionFactory = buildSessionFactory(Person.class, true);
final StatisticsImplementor statistics = sessionFactory.getStatistics();
inTransaction(sessionFactory, s -> s.persist(new Person("1", "John Doe", true)));
// this time it should be iun the cache because we enabled JPA compliance
assertEquals(statistics.getSecondLevelCachePutCount(), 1);
assertTrue(sessionFactory.getCache().contains(Person.class, "1"));
inTransaction(sessionFactory, s -> {
statistics.clear();
final Person person = s.get(Person.class, "1");
assertTrue(Hibernate.isInitialized(person));
assertThat(statistics.getSecondLevelCacheHitCount(), CoreMatchers.is(1L));
statistics.clear();
});
}
use of org.hibernate.stat.spi.StatisticsImplementor in project hibernate-orm by hibernate.
the class CachingWithSecondaryTablesTests method testVersioned.
@Test
public void testVersioned() {
sessionFactory = buildSessionFactory(VersionedPerson.class, false);
final StatisticsImplementor statistics = sessionFactory.getStatistics();
inTransaction(sessionFactory, s -> s.persist(new VersionedPerson("1", "John Doe", true)));
// versioned data should be cacheable regardless
assertEquals(statistics.getSecondLevelCachePutCount(), 1);
assertTrue(sessionFactory.getCache().contains(VersionedPerson.class, "1"));
inTransaction(sessionFactory, s -> {
statistics.clear();
final VersionedPerson person = s.get(VersionedPerson.class, "1");
assertTrue(Hibernate.isInitialized(person));
assertThat(statistics.getSecondLevelCacheHitCount(), CoreMatchers.is(1L));
statistics.clear();
});
}
Aggregations