FileDocCategorySizeDatePackage
TestLazyPropertyCustomTypeExecutable.javaAPI DocHibernate 3.2.51992Mon Nov 13 06:49:02 GMT 2006org.hibernate.test.instrument.cases

TestLazyPropertyCustomTypeExecutable

public class TestLazyPropertyCustomTypeExecutable extends AbstractExecutable
{@inheritDoc}
author
Steve Ebersole

Fields Summary
Constructors Summary
Methods Summary
protected voidcleanup()

		Session s = getFactory().openSession();
		s.beginTransaction();
		Iterator itr = s.createQuery( "from Problematic" ).list().iterator();
		while ( itr.hasNext() ) {
			Problematic p = (Problematic) itr.next();
			s.delete( p );
		}
		s.getTransaction().commit();
		s.close();
	
public voidexecute()

		Session s = getFactory().openSession();
		s.beginTransaction();
		Problematic p = new Problematic();
		p.setName( "whatever" );
		p.setBytes( new byte[] { 1, 0, 1, 1, 0 } );
		s.save( p );
		s.getTransaction().commit();
		s.close();

		// this access should be ok because p1 is not a lazy proxy 
		s = getFactory().openSession();
		s.beginTransaction();
		Problematic p1 = (Problematic) s.get( Problematic.class, p.getId() );
		Assert.assertTrue( FieldInterceptionHelper.isInstrumented( p1 ) );
		p1.getRepresentation();
		s.getTransaction().commit();
		s.close();
		
		s = getFactory().openSession();
		s.beginTransaction();
		p1 = (Problematic) s.createQuery( "from Problematic" ).setReadOnly(true ).list().get( 0 );
		p1.getRepresentation();
		s.getTransaction().commit();
		s.close();
		
		s = getFactory().openSession();
		s.beginTransaction();
		p1 = (Problematic) s.load( Problematic.class, p.getId() );
		Assert.assertFalse( FieldInterceptionHelper.isInstrumented( p1 ) );
		p1.setRepresentation( p.getRepresentation() );
		s.getTransaction().commit();
		s.close();
	
protected java.lang.String[]getResources()

		return new String[] { "org/hibernate/test/instrument/domain/Problematic.hbm.xml" };