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();
});
}
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");
}
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);
}
Aggregations