use of org.hibernate.stat.SessionStatistics in project hibernate-orm by hibernate.
the class SessionStatsTest method testSessionStatistics.
@Test
public void testSessionStatistics() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Statistics stats = sessionFactory().getStatistics();
stats.clear();
boolean isStats = stats.isStatisticsEnabled();
stats.setStatisticsEnabled(true);
Continent europe = fillDb(s);
tx.commit();
s.clear();
tx = s.beginTransaction();
SessionStatistics sessionStats = s.getStatistics();
assertEquals(0, sessionStats.getEntityKeys().size());
assertEquals(0, sessionStats.getEntityCount());
assertEquals(0, sessionStats.getCollectionKeys().size());
assertEquals(0, sessionStats.getCollectionCount());
europe = (Continent) s.get(Continent.class, europe.getId());
Hibernate.initialize(europe.getCountries());
Hibernate.initialize(europe.getCountries().iterator().next());
assertEquals(2, sessionStats.getEntityKeys().size());
assertEquals(2, sessionStats.getEntityCount());
assertEquals(1, sessionStats.getCollectionKeys().size());
assertEquals(1, sessionStats.getCollectionCount());
tx.commit();
s.close();
stats.setStatisticsEnabled(isStats);
}
use of org.hibernate.stat.SessionStatistics in project wildfly by wildfly.
the class SFSBHibernate2LcacheStats method prepareData.
// create planet
public Planet prepareData(String planetName, String galaxyName, String starName, Set<Satellite> satellites, Integer id) {
Session session = sessionFactory.openSession();
Planet planet = new Planet();
planet.setPlanetId(id);
planet.setPlanetName(planetName);
planet.setGalaxy(galaxyName);
planet.setStar(starName);
// Transaction trans = session.beginTransaction();
try {
session.save(planet);
if (satellites != null && satellites.size() > 0) {
Iterator<Satellite> itrSat = satellites.iterator();
while (itrSat.hasNext()) {
Satellite sat = itrSat.next();
session.save(sat);
}
planet.setSatellites(new HashSet<Satellite>());
planet.getSatellites().addAll(satellites);
}
session.saveOrUpdate(planet);
SessionStatistics stats = session.getStatistics();
assertEquals(2, stats.getEntityKeys().size());
assertEquals(2, stats.getEntityCount());
// session.flush();
// session.close();
} catch (Exception e) {
throw new RuntimeException("transactional failure while persisting planet entity", e);
}
// trans.commit();
session.close();
return planet;
}
Aggregations