|
From: <hib...@li...> - 2006-05-02 15:09:47
|
Author: ste...@jb...
Date: 2006-05-02 11:09:11 -0400 (Tue, 02 May 2006)
New Revision: 9853
Modified:
branches/Branch_3_1/Hibernate3/src/org/hibernate/proxy/AbstractLazyInitializer.java
branches/Branch_3_1/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java
Log:
HHH-1695 : subsequent access on non-existent proxy
Modified: branches/Branch_3_1/Hibernate3/src/org/hibernate/proxy/AbstractLazyInitializer.java
===================================================================
--- branches/Branch_3_1/Hibernate3/src/org/hibernate/proxy/AbstractLazyInitializer.java 2006-05-02 14:32:27 UTC (rev 9852)
+++ branches/Branch_3_1/Hibernate3/src/org/hibernate/proxy/AbstractLazyInitializer.java 2006-05-02 15:09:11 UTC (rev 9853)
@@ -66,6 +66,11 @@
}
}
}
+ else {
+ if ( !unwrap ) {
+ ObjectNotFoundException.throwIfNull(target, id, entityName);
+ }
+ }
}
public final void setSession(SessionImplementor s) throws HibernateException {
Modified: branches/Branch_3_1/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java
===================================================================
--- branches/Branch_3_1/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java 2006-05-02 14:32:27 UTC (rev 9852)
+++ branches/Branch_3_1/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java 2006-05-02 15:09:11 UTC (rev 9853)
@@ -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;
@@ -203,6 +204,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" };
|