use of org.hibernate.stat.Statistics in project hibernate-orm by hibernate.
the class EhCacheTest method testEmptySecondLevelCacheEntry.
@Test
public void testEmptySecondLevelCacheEntry() throws Exception {
sessionFactory().getCache().evictEntityRegion(Item.class.getName());
Statistics stats = sessionFactory().getStatistics();
stats.clear();
SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics(Item.class.getName());
Map cacheEntries = statistics.getEntries();
assertEquals(0, cacheEntries.size());
}
use of org.hibernate.stat.Statistics in project hibernate-orm by hibernate.
the class ReadWriteTest method testAddNewOneToManyElementNoInitFlushInitLeaveCacheConsistent.
@Test
public void testAddNewOneToManyElementNoInitFlushInitLeaveCacheConsistent() throws Exception {
Statistics stats = sessionFactory().getStatistics();
stats.clear();
SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items");
ByRef<Long> itemId = new ByRef<>(null);
saveItem(itemId);
// create an element for item.bagOfItems
Item itemElement = new Item();
itemElement.setName("element");
itemElement.setDescription("element item");
withTxSession(s -> {
Item item = s.get(Item.class, itemId.get());
assertFalse(Hibernate.isInitialized(item.getBagOfItems()));
item.addItemToBag(itemElement);
assertFalse(Hibernate.isInitialized(item.getBagOfItems()));
s.persist(itemElement);
s.flush();
Hibernate.initialize(item.getBagOfItems());
markRollbackOnly(s);
});
withTxSession(s -> {
Item item = s.get(Item.class, itemId.get());
Hibernate.initialize(item.getBagOfItems());
assertTrue(item.getBagOfItems().isEmpty());
s.delete(item);
});
}
use of org.hibernate.stat.Statistics in project hibernate-orm by hibernate.
the class ReadWriteTest method testAddNewOneToManyElementInitFlushLeaveCacheConsistent.
@Test
@TestForIssue(jiraKey = "HHH-9231")
public void testAddNewOneToManyElementInitFlushLeaveCacheConsistent() throws Exception {
Statistics stats = sessionFactory().getStatistics();
stats.clear();
SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items");
ByRef<Long> itemId = new ByRef<>(null);
saveItem(itemId);
// create an element for item.itsms
Item itemElement = new Item();
itemElement.setName("element");
itemElement.setDescription("element item");
withTxSession(s -> {
Item item = s.get(Item.class, itemId.get());
assertFalse(Hibernate.isInitialized(item.getItems()));
item.addItem(itemElement);
assertTrue(Hibernate.isInitialized(item.getItems()));
s.persist(itemElement);
s.flush();
markRollbackOnly(s);
});
withTxSession(s -> {
Item item = s.get(Item.class, itemId.get());
Hibernate.initialize(item.getItems());
assertTrue(item.getItems().isEmpty());
s.delete(item);
});
}
use of org.hibernate.stat.Statistics in project hibernate-orm by hibernate.
the class ReadWriteTest method testAddNewOneToManyElementNoInitFlushLeaveCacheConsistent.
@Test
@TestForIssue(jiraKey = "HHH-9231")
public void testAddNewOneToManyElementNoInitFlushLeaveCacheConsistent() throws Exception {
Statistics stats = sessionFactory().getStatistics();
stats.clear();
SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items");
ByRef<Long> itemId = new ByRef<>(null);
saveItem(itemId);
// create an element for item.bagOfItems
Item itemElement = new Item();
itemElement.setName("element");
itemElement.setDescription("element item");
withTxSession(s -> {
Item item = s.get(Item.class, itemId.get());
assertFalse(Hibernate.isInitialized(item.getItems()));
item.addItemToBag(itemElement);
assertFalse(Hibernate.isInitialized(item.getBagOfItems()));
s.persist(itemElement);
s.flush();
markRollbackOnly(s);
});
withTxSession(s -> {
Item item = s.get(Item.class, itemId.get());
Hibernate.initialize(item.getItems());
assertTrue(item.getItems().isEmpty());
s.delete(item);
});
}
use of org.hibernate.stat.Statistics in project hibernate-orm by hibernate.
the class ReadOnlyTest method testEmptySecondLevelCacheEntry.
@Test
public void testEmptySecondLevelCacheEntry() throws Exception {
sessionFactory().getCache().evictCollectionRegion(Item.class.getName() + ".items");
Statistics stats = sessionFactory().getStatistics();
stats.clear();
SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items");
Map cacheEntries = statistics.getEntries();
assertEquals(0, cacheEntries.size());
}
Aggregations