1
package org.hibernate.test.instrument.cases;
3
import java.util.Iterator;
5
import junit.framework.Assert;
7
import org.hibernate.Session;
8
import org.hibernate.intercept.FieldInterceptionHelper;
9
import org.hibernate.test.instrument.domain.Problematic;
14
* @author Steve Ebersole
16
public class TestLazyPropertyCustomTypeExecutable extends AbstractExecutable {
18
protected String[] getResources() {
19
return new String[] { "org/hibernate/test/instrument/domain/Problematic.hbm.xml" };
22
public void execute() {
23
Session s = getFactory().openSession();
25
Problematic p = new Problematic();
26
p.setName( "whatever" );
27
p.setBytes( new byte[] { 1, 0, 1, 1, 0 } );
29
s.getTransaction().commit();
32
// this access should be ok because p1 is not a lazy proxy
33
s = getFactory().openSession();
35
Problematic p1 = (Problematic) s.get( Problematic.class, p.getId() );
36
Assert.assertTrue( FieldInterceptionHelper.isInstrumented( p1 ) );
37
p1.getRepresentation();
38
s.getTransaction().commit();
41
s = getFactory().openSession();
43
p1 = (Problematic) s.createQuery( "from Problematic" ).setReadOnly(true ).list().get( 0 );
44
p1.getRepresentation();
45
s.getTransaction().commit();
48
s = getFactory().openSession();
50
p1 = (Problematic) s.load( Problematic.class, p.getId() );
51
Assert.assertFalse( FieldInterceptionHelper.isInstrumented( p1 ) );
52
p1.setRepresentation( p.getRepresentation() );
53
s.getTransaction().commit();
57
protected void cleanup() {
58
Session s = getFactory().openSession();
60
Iterator itr = s.createQuery( "from Problematic" ).list().iterator();
61
while ( itr.hasNext() ) {
62
Problematic p = (Problematic) itr.next();
65
s.getTransaction().commit();
b'\\ No newline at end of file'