[hibernate-commits] Hibernate SVN: r10790 - in trunk/Hibernate3: src/org/hibernate/persister/entity test/org/hibernate/test/instrument/buildtime test/org/hibernate/test/instrument/cases

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Nov 13 09:14:49 EST 2006


Author: max.andersen at jboss.com
Date: 2006-11-13 09:14:45 -0500 (Mon, 13 Nov 2006)
New Revision: 10790

Modified:
   trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
   trunk/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java
   trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java
Log:
HHH-2236 Lazy property + setReadOnly + Instrumented classes results in NullPointerException when accessing lazy property
(merged from branch_3_2)

Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java	2006-11-13 13:49:01 UTC (rev 10789)
+++ trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java	2006-11-13 14:14:45 UTC (rev 10790)
@@ -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: trunk/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java	2006-11-13 13:49:01 UTC (rev 10789)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/buildtime/InstrumentTest.java	2006-11-13 14:14:45 UTC (rev 10790)
@@ -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: trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java	2006-11-13 13:49:01 UTC (rev 10789)
+++ trunk/Hibernate3/test/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java	2006-11-13 14:14:45 UTC (rev 10790)
@@ -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




More information about the hibernate-commits mailing list