Author: max.andersen(a)jboss.com
Date: 2006-11-13 08:49:01 -0500 (Mon, 13 Nov 2006)
New Revision: 10789
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java
Log:
HHH-2236 Lazy property + setReadOnly + Instrumented classes results in
NullPointerException when accessing lazy property
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
---
branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-11-13
13:21:19 UTC (rev 10788)
+++
branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-11-13
13:49:01 UTC (rev 10789)
@@ -850,7 +850,11 @@
final Object propValue
) {
setPropertyValue( entity, lazyPropertyNumbers[j], propValue, session.getEntityMode()
);
- snapshot[ lazyPropertyNumbers[j] ] = lazyPropertyTypes[j].deepCopy( propValue,
session.getEntityMode(), factory );
+
+ if (snapshot != null) { // object have been loaded with setReadOnly(true); HHH-2236
+ snapshot[ lazyPropertyNumbers[j] ] = lazyPropertyTypes[j].deepCopy( propValue,
session.getEntityMode(), factory );
+ }
+
return fieldName.equals( lazyPropertyNames[j] );
}
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java
===================================================================
---
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java 2006-11-13
13:21:19 UTC (rev 10788)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java 2006-11-13
13:49:01 UTC (rev 10789)
@@ -13,6 +13,7 @@
import org.hibernate.test.instrument.cases.TestLazyManyToOneExecutable;
import org.hibernate.test.instrument.cases.TestInjectFieldInterceptorExecutable;
import org.hibernate.test.instrument.cases.TestIsPropertyInitializedExecutable;
+import org.hibernate.test.instrument.cases.TestLazyPropertyCustomTypeExecutable;
import org.hibernate.test.instrument.cases.TestManyToOneProxyExecutable;
import org.hibernate.test.instrument.cases.Executable;
@@ -53,6 +54,10 @@
execute( new TestManyToOneProxyExecutable() );
}
+ public void testLazyPropertyCustomTypeExecutable() {
+ execute( new TestLazyPropertyCustomTypeExecutable() );
+ }
+
private void execute(Executable executable) {
executable.prepare();
try {
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java
===================================================================
---
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java 2006-11-13
13:21:19 UTC (rev 10788)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java 2006-11-13
13:49:01 UTC (rev 10789)
@@ -29,28 +29,25 @@
s.getTransaction().commit();
s.close();
- // this access should be ok because p1 is not a lazy proxy
+ // 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() );
+ Problematic p1 = (Problematic) s.get( Problematic.class, p.getId() );
Assert.assertTrue( FieldInterceptionHelper.isInstrumented( p1 ) );
p1.getRepresentation();
s.getTransaction().commit();
s.close();
-
- // this should cause problems
+
s = getFactory().openSession();
s.beginTransaction();
- p1 = ( Problematic ) s.load( Problematic.class, p.getId() );
- Assert.assertFalse( FieldInterceptionHelper.isInstrumented( p1 ) );
+ p1 = (Problematic) s.createQuery( "from Problematic" ).setReadOnly(true
).list().get( 0 );
p1.getRepresentation();
s.getTransaction().commit();
s.close();
-
- // this should cause problems
+
s = getFactory().openSession();
s.beginTransaction();
- p1 = ( Problematic ) s.load( Problematic.class, p.getId() );
+ p1 = (Problematic) s.load( Problematic.class, p.getId() );
Assert.assertFalse( FieldInterceptionHelper.isInstrumented( p1 ) );
p1.setRepresentation( p.getRepresentation() );
s.getTransaction().commit();
@@ -61,11 +58,11 @@
Session s = getFactory().openSession();
s.beginTransaction();
Iterator itr = s.createQuery( "from Problematic" ).list().iterator();
- while( itr.hasNext() ) {
- Problematic p = ( Problematic ) itr.next();
+ while ( itr.hasNext() ) {
+ Problematic p = (Problematic) itr.next();
s.delete( p );
}
s.getTransaction().commit();
s.close();
}
-}
+}
\ No newline at end of file
Show replies by date