use of org.hibernate.cache.spi.DomainDataRegion in project hibernate-orm by hibernate.
the class BasicUnstructuredCachingOfConvertedValueTest method basicCacheStructureTest.
@Test
@TestForIssue(jiraKey = "HHH-9615")
@SuppressWarnings("unchecked")
public void basicCacheStructureTest() {
EntityPersister persister = sessionFactory().getMetamodel().entityPersisters().get(Address.class.getName());
final DomainDataRegion region = persister.getCacheAccessStrategy().getRegion();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test during store...
PostalAreaConverter.clearCounts();
Session session = openSession();
session.getTransaction().begin();
session.save(new Address(1, "123 Main St.", null, PostalArea._78729));
session.getTransaction().commit();
session.close();
{
inSession(s -> {
final EntityDataAccess entityDataAccess = region.getEntityDataAccess(persister.getNavigableRole());
final Object cacheKey = entityDataAccess.generateCacheKey(1, persister, sessionFactory(), null);
final Object cachedItem = entityDataAccess.get(s, cacheKey);
final StandardCacheEntryImpl state = (StandardCacheEntryImpl) cachedItem;
// this is the point of the Jira.. that this "should be" the converted value
assertThat(state.getDisassembledState()[postalAreaAttributeIndex], instanceOf(PostalArea.class));
});
}
assertThat(PostalAreaConverter.toDatabaseCallCount, is(1));
assertThat(PostalAreaConverter.toDomainCallCount, is(0));
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test during load...
PostalAreaConverter.clearCounts();
sessionFactory().getCache().evictAll();
session = openSession();
session.getTransaction().begin();
Address address = session.get(Address.class, 1);
session.getTransaction().commit();
session.close();
{
inSession(s -> {
final EntityDataAccess entityDataAccess = region.getEntityDataAccess(persister.getNavigableRole());
final Object cacheKey = entityDataAccess.generateCacheKey(1, persister, sessionFactory(), null);
final Object cachedItem = entityDataAccess.get(s, cacheKey);
final StandardCacheEntryImpl state = (StandardCacheEntryImpl) cachedItem;
// this is the point of the Jira.. that this "should be" the converted value
assertThat(state.getDisassembledState()[postalAreaAttributeIndex], instanceOf(PostalArea.class));
});
}
assertThat(PostalAreaConverter.toDatabaseCallCount, is(0));
assertThat(PostalAreaConverter.toDomainCallCount, is(1));
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// cleanup
session = openSession();
session.getTransaction().begin();
session.delete(address);
session.getTransaction().commit();
session.close();
}
Aggregations