sessionFactory.getCache().evictEntityRegion(Item.class);
SecondLevelCacheStatistics slcs = getSecondLevelCacheStatistics(Item.class);
Session session;
log.debug("Item 저장 - #1");
Item item = new Item();
item.setName("redis");
item.setDescription("redis cache item");
session = sessionFactory.openSession();
session.save(item);
session.flush();
session.close();
log.debug("Item 조회 - #1");
session = sessionFactory.openSession();
Item loaded = (Item) session.get(Item.class, item.getId());
assertThat(loaded).isNotNull();
session.close();
log.info(slcs.toString());
// assertThat(slcs.getPutCount()).isEqualTo(1);
// assertThat(slcs.getElementCountInMemory()).isEqualTo(1);
log.debug("Item Update - #1");
session = sessionFactory.openSession();
// session.merge(loaded);
loaded.setDescription("Update description...");
session.saveOrUpdate(loaded);
session.flush();
session.close();
log.debug("Item 조회 - #2");
session = sessionFactory.openSession();
loaded = (Item) session.get(Item.class, loaded.getId());
assertThat(loaded).isNotNull();
assertThat(loaded.getId()).isEqualTo(item.getId());
assertThat(loaded.getDescription()).isNotEqualTo(item.getDescription());
session.close();
log.debug("Item 조회 - #3");
session = sessionFactory.openSession();
loaded = (Item) session.get(Item.class, loaded.getId());
assertThat(loaded).isNotNull();
assertThat(loaded.getId()).isEqualTo(item.getId());
assertThat(loaded.getDescription()).isNotEqualTo(item.getDescription());
session.close();
log.debug("Item 조회 - #4");
session = sessionFactory.openSession();
loaded = (Item) session.get(Item.class, loaded.getId());
assertThat(loaded).isNotNull();
assertThat(loaded.getId()).isEqualTo(item.getId());
assertThat(loaded.getDescription()).isNotEqualTo(item.getDescription());
session.close();
log.info(slcs.toString());
// assertThat(slcs.getPutCount()).isEqualTo(1);
// assertThat(slcs.getElementCountInMemory()).isEqualTo(1);