FileDocCategorySizeDatePackage
InstrumentCacheTest2.javaAPI DocHibernate 3.2.52356Tue Dec 12 16:22:26 GMT 2006org.hibernate.test.lazycache

InstrumentCacheTest2

public class InstrumentCacheTest2 extends org.hibernate.junit.functional.FunctionalTestCase
author
Gavin King

Fields Summary
Constructors Summary
public InstrumentCacheTest2(String str)

		super(str);
	
Methods Summary
public voidconfigure(org.hibernate.cfg.Configuration cfg)

		cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
	
public java.lang.String[]getMappings()

		return new String[] { "lazycache/Documents.hbm.xml" };
	
public static booleanisRunnable()

		return FieldInterceptionHelper.isInstrumented( new Document() );
	
public static junit.framework.Testsuite()

		return new FunctionalTestClassTestSuite( InstrumentCacheTest2.class );
	
public voidtestInitFromCache()

		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();