Search in sources :

Example 11 with CacheImplementor

use of org.hibernate.cache.spi.CacheImplementor in project hibernate-orm by hibernate.

the class InheritedNaturalIdCacheTest method testLoadWrongClassByIdFromCache.

@Test
public void testLoadWrongClassByIdFromCache(SessionFactoryScope scope) {
    clearCaches(scope);
    // load `MyEntity#1` into the cache
    scope.inTransaction((session) -> {
        final MyEntity loaded = session.byId(MyEntity.class).load(1);
        assertThat(loaded).isNotNull();
    });
    final CacheImplementor cache = scope.getSessionFactory().getCache();
    assertThat(cache.containsEntity(MyEntity.class, 1)).isTrue();
    // now try to access it as an ExtendedEntity
    scope.inTransaction((session) -> {
        final ExtendedEntity loaded = session.byId(ExtendedEntity.class).load(1);
        assertThat(loaded).isNull();
    });
}
Also used : CacheImplementor(org.hibernate.cache.spi.CacheImplementor) Test(org.junit.jupiter.api.Test)

Example 12 with CacheImplementor

use of org.hibernate.cache.spi.CacheImplementor in project hibernate-orm by hibernate.

the class OneToOneCacheTest method OneToOneTest.

private <TPerson extends Person, TDetails extends Details> void OneToOneTest(Class<TPerson> personClass, Class<TDetails> detailsClass, SessionFactoryScope scope) throws Exception {
    // Initialize the database with data.
    List<Object> ids = createPersonsAndDetails(personClass, detailsClass, scope);
    // Clear the second level cache and the statistics.
    SessionFactoryImplementor sfi = scope.getSessionFactory();
    CacheImplementor cache = sfi.getCache();
    StatisticsImplementor statistics = sfi.getStatistics();
    cache.evictEntityData(personClass);
    cache.evictEntityData(detailsClass);
    cache.evictQueryRegions();
    statistics.clear();
    // Fill the empty caches with data.
    this.getPersons(personClass, ids, scope);
    // Verify that no data was retrieved from the cache.
    assertEquals(0, statistics.getSecondLevelCacheHitCount(), "Second level cache hit count");
    statistics.clear();
    this.getPersons(personClass, ids, scope);
    // Verify that all data was retrieved from the cache.
    assertEquals(0, statistics.getSecondLevelCacheMissCount(), "Second level cache miss count");
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) CacheImplementor(org.hibernate.cache.spi.CacheImplementor)

Example 13 with CacheImplementor

use of org.hibernate.cache.spi.CacheImplementor in project quarkus by quarkusio.

the class JPACacheDisabledTest method testNTransaction.

@Test
@Transactional
public void testNTransaction() {
    CacheImplementor cache = (CacheImplementor) session.getSessionFactory().getCache();
    TimestampsCache timestampsCache = cache.getTimestampsCache();
    Assertions.assertNull(timestampsCache);
}
Also used : TimestampsCache(org.hibernate.cache.spi.TimestampsCache) CacheImplementor(org.hibernate.cache.spi.CacheImplementor) Test(org.junit.jupiter.api.Test) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Transactional(javax.transaction.Transactional)

Aggregations

CacheImplementor (org.hibernate.cache.spi.CacheImplementor)13 Test (org.junit.jupiter.api.Test)7 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)1 Query (jakarta.persistence.Query)1 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)1 Transactional (javax.transaction.Transactional)1 SessionFactory (org.hibernate.SessionFactory)1 WrongClassException (org.hibernate.WrongClassException)1 NamedNativeQuery (org.hibernate.annotations.NamedNativeQuery)1 DomainDataRegion (org.hibernate.cache.spi.DomainDataRegion)1 QueryResultsCache (org.hibernate.cache.spi.QueryResultsCache)1 Region (org.hibernate.cache.spi.Region)1 TimestampsCache (org.hibernate.cache.spi.TimestampsCache)1 StatisticsImplementor (org.hibernate.stat.spi.StatisticsImplementor)1 TestForIssue (org.hibernate.testing.TestForIssue)1 QuarkusInfinispanRegionFactory (org.infinispan.quarkus.hibernate.cache.QuarkusInfinispanRegionFactory)1 Test (org.junit.Test)1 AfterEach (org.junit.jupiter.api.AfterEach)1