Code example for SessionFactory

Methods: getCurrentSessiongetStatistics

0
		TransactionDefinition def = new DefaultTransactionDefinition();
		 
		TransactionStatus tx = txManager.getTransaction(def);
		Person person = new Person();
		person.initUid();
		sessionFactory.getCurrentSession().persist(person);
		txManager.commit(tx);
		 
		tx = txManager.getTransaction(def);
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Person.class);
		criteria.add(Restrictions.idEq(person.getId()));
		person = (Person)criteria.uniqueResult();
		txManager.commit(tx);
		 
        Person result = (Person)initializeObject(person, new String[] { "contacts" });
         
        ClassGetter classGetter = ((ConvertersConfig)GraniteContext.getCurrentInstance().getGraniteConfig()).getClassGetter();
        Assert.assertTrue("Person initialized", classGetter.isInitialized(null, null, result));
        Assert.assertTrue("Collection initialized", classGetter.isInitialized(result, "contacts", result.getContacts()));
         
		Assert.assertEquals("Sessions closed", sessionFactory.getStatistics().getSessionOpenCount(), 
				sessionFactory.getStatistics().getSessionCloseCount());
    } 
}