From: <hib...@li...> - 2006-05-02 15:11:55
|
Author: ste...@jb... Date: 2006-05-02 11:11:17 -0400 (Tue, 02 May 2006) New Revision: 9854 Modified: trunk/Hibernate3/src/org/hibernate/proxy/AbstractLazyInitializer.java trunk/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java Log: HHH-1695 : subsequent access on non-existent proxy Modified: trunk/Hibernate3/src/org/hibernate/proxy/AbstractLazyInitializer.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/proxy/AbstractLazyInitializer.java 2006-05-02 15:09:11 UTC (rev 9853) +++ trunk/Hibernate3/src/org/hibernate/proxy/AbstractLazyInitializer.java 2006-05-02 15:11:17 UTC (rev 9854) @@ -70,6 +70,11 @@ } } } + else { + if ( !unwrap ) { + ObjectNotFoundException.throwIfNull(target, id, entityName); + } + } } public final void setSession(SessionImplementor s) throws HibernateException { Modified: trunk/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java 2006-05-02 15:09:11 UTC (rev 9853) +++ trunk/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java 2006-05-02 15:11:17 UTC (rev 9854) @@ -12,6 +12,7 @@ import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.FlushMode; +import org.hibernate.ObjectNotFoundException; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.impl.SessionImpl; @@ -154,7 +155,7 @@ sclone.close(); } - + public void testProxy() { Session s = openSession(); Transaction t = s.beginTransaction(); @@ -204,6 +205,38 @@ s.close(); } + public void testSubsequentNonExistentProxyAccess() { + Session s = openSession(); + Transaction t = s.beginTransaction(); + + DataPoint proxy = ( DataPoint ) s.load( DataPoint.class, new Long(-1) ); + assertFalse( Hibernate.isInitialized( proxy ) ); + try { + proxy.getDescription(); + fail( "proxy access did not fail on non-existent proxy" ); + } + catch( ObjectNotFoundException onfe ) { + // expected + } + catch( Throwable e ) { + fail( "unexpected exception type on non-existent proxy access : " + e ); + } + // try it a second (subsequent) time... + try { + proxy.getDescription(); + fail( "proxy access did not fail on non-existent proxy" ); + } + catch( ObjectNotFoundException onfe ) { + // expected + } + catch( Throwable e ) { + fail( "unexpected exception type on non-existent proxy access : " + e ); + } + + t.commit(); + s.close(); + } + protected String[] getMappings() { return new String[] { "proxy/DataPoint.hbm.xml" }; |