protected Set<DummyProperty> getPropertiesOfEntity(SessionFactory sf, long entityId) {
   Session session = sf.openSession();
   DummyEntity entity = (DummyEntity) session.get(DummyEntity.class, entityId);
   if (entity != null) {
     return entity.getProperties();
   } else {
     return null;
   }
 }
  @Test
  public void testEntity() {
    final HazelcastInstance hz = getHazelcastInstance(sf);
    assertNotNull(hz);
    final int count = 100;
    final int childCount = 3;
    insertDummyEntities(count, childCount);
    List<DummyEntity> list = new ArrayList<DummyEntity>(count);
    Session session = sf.openSession();
    try {
      for (int i = 0; i < count; i++) {
        DummyEntity e = (DummyEntity) session.get(DummyEntity.class, (long) i);
        session.evict(e);
        list.add(e);
      }
    } finally {
      session.close();
    }
    session = sf.openSession();
    Transaction tx = session.beginTransaction();
    try {
      for (DummyEntity dummy : list) {
        dummy.setDate(new Date());
        session.update(dummy);
      }
      tx.commit();
    } catch (Exception e) {
      tx.rollback();
      e.printStackTrace();
    } finally {
      session.close();
    }

    Statistics stats = sf.getStatistics();
    Map<?, ?> cache = hz.getMap(DummyEntity.class.getName());
    Map<?, ?> propCache = hz.getMap(DummyProperty.class.getName());
    Map<?, ?> propCollCache = hz.getMap(DummyEntity.class.getName() + ".properties");
    assertEquals((childCount + 1) * count, stats.getEntityInsertCount());
    // twice put of entity and properties (on load and update) and once put of collection
    // TODO: fix next assertion ->
    //        assertEquals((childCount + 1) * count * 2, stats.getSecondLevelCachePutCount());
    assertEquals(childCount * count, stats.getEntityLoadCount());
    assertEquals(count, stats.getSecondLevelCacheHitCount());
    // collection cache miss
    assertEquals(count, stats.getSecondLevelCacheMissCount());
    assertEquals(count, cache.size());
    assertEquals(count * childCount, propCache.size());
    assertEquals(count, propCollCache.size());
    sf.getCache().evictEntityRegion(DummyEntity.class);
    sf.getCache().evictEntityRegion(DummyProperty.class);
    assertEquals(0, cache.size());
    assertEquals(0, propCache.size());
    stats.logSummary();
  }
  @Test
  public void testInsertGetUpdateGet() {
    Session session = sf.openSession();
    DummyEntity e = new DummyEntity(1L, "test", 0d, null);
    Transaction tx = session.beginTransaction();
    try {
      session.save(e);
      tx.commit();
    } catch (Exception ex) {
      ex.printStackTrace();
      tx.rollback();
      fail(ex.getMessage());
    } finally {
      session.close();
    }

    session = sf.openSession();
    try {
      e = (DummyEntity) session.get(DummyEntity.class, 1L);
      assertEquals("test", e.getName());
      assertNull(e.getDate());
    } catch (Exception ex) {
      ex.printStackTrace();
      fail(ex.getMessage());
    } finally {
      session.close();
    }

    session = sf.openSession();
    tx = session.beginTransaction();
    try {
      e = (DummyEntity) session.get(DummyEntity.class, 1L);
      assertEquals("test", e.getName());
      assertNull(e.getDate());
      e.setName("dummy");
      e.setDate(new Date());
      session.update(e);
      tx.commit();
    } catch (Exception ex) {
      ex.printStackTrace();
      tx.rollback();
      fail(ex.getMessage());
    } finally {
      session.close();
    }

    session = sf.openSession();
    try {
      e = (DummyEntity) session.get(DummyEntity.class, 1L);
      assertEquals("dummy", e.getName());
      Assert.assertNotNull(e.getDate());
    } catch (Exception ex) {
      ex.printStackTrace();
      fail(ex.getMessage());
    } finally {
      session.close();
    }
    //        stats.logSummary();
  }
 @Test
 public void testInsertEvictUpdate() {
   insertDummyEntities(1);
   Session session = sf.openSession();
   Transaction tx = session.beginTransaction();
   DummyEntity ent = (DummyEntity) session.get(DummyEntity.class, 0L);
   sf.getCache().evictEntity("com.hazelcast.hibernate.entity.DummyEntity", 0L);
   ent.setName("updatedName");
   session.update(ent);
   tx.commit();
   session.close();
   ArrayList<DummyEntity> list = getDummyEntities(sf, 1);
   assertEquals("updatedName", list.get(0).getName());
 }
 protected void updateDummyEntityName(SessionFactory sf, long id, String newName) {
   Session session = null;
   Transaction txn = null;
   try {
     session = sf.openSession();
     txn = session.beginTransaction();
     DummyEntity entityToUpdate = (DummyEntity) session.get(DummyEntity.class, id);
     entityToUpdate.setName(newName);
     session.update(entityToUpdate);
     txn.commit();
   } catch (RuntimeException e) {
     txn.rollback();
     e.printStackTrace();
     throw e;
   } finally {
     session.close();
   }
 }