Search in sources :

Example 6 with StatisticsImplementor

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();
    });
}
Also used : StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) Test(org.junit.Test)

Example 7 with StatisticsImplementor

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();
    });
}
Also used : StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) Test(org.junit.Test)

Example 8 with StatisticsImplementor

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();
    });
}
Also used : StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) Test(org.junit.Test)

Aggregations

StatisticsImplementor (org.hibernate.stat.spi.StatisticsImplementor)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HibernateException (org.hibernate.HibernateException)1 Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 EntityStatistics (org.hibernate.stat.EntityStatistics)1 QueryStatistics (org.hibernate.stat.QueryStatistics)1 SecondLevelCacheStatistics (org.hibernate.stat.SecondLevelCacheStatistics)1 StatisticsFactory (org.hibernate.stat.spi.StatisticsFactory)1