Session s;
Transaction tx;
s = getSessions().openSession();
tx = s.beginTransaction();
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
tx.commit();
s.close();
s = getSessions().openSession();
tx = s.beginTransaction();
s.createQuery("from Document fetch all properties").uniqueResult();
tx.commit();
s.close();
getSessions().getStatistics().clear();
s = getSessions().openSession();
tx = s.beginTransaction();
Document d = (Document) s.createCriteria(Document.class).uniqueResult();
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
assertFalse( Hibernate.isPropertyInitialized(d, "summary") );
assertEquals( "Hibernate is....", d.getText() );
assertTrue( Hibernate.isPropertyInitialized(d, "text") );
assertTrue( Hibernate.isPropertyInitialized(d, "summary") );
tx.commit();
s.close();
assertEquals( 1, getSessions().getStatistics().getPrepareStatementCount() );
s = getSessions().openSession();
tx = s.beginTransaction();
d = (Document) s.get(Document.class, d.getId());
assertTrue( Hibernate.isPropertyInitialized(d, "text") );
assertTrue( Hibernate.isPropertyInitialized(d, "summary") );
tx.commit();
s.close();