[hibernate-commits] Hibernate SVN: r14159 - core/branches/Branch_3_2/test/org/hibernate/test/discriminator.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Oct 30 20:13:38 EDT 2007


Author: gbadner
Date: 2007-10-30 20:13:38 -0400 (Tue, 30 Oct 2007)
New Revision: 14159

Modified:
   core/branches/Branch_3_2/test/org/hibernate/test/discriminator/DiscriminatorTest.java
Log:
HHH-2921 : added test cases that execute polymorphic queries when there is a superclass proxy for the resulting entity in the session cache


Modified: core/branches/Branch_3_2/test/org/hibernate/test/discriminator/DiscriminatorTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/discriminator/DiscriminatorTest.java	2007-10-29 23:27:09 UTC (rev 14158)
+++ core/branches/Branch_3_2/test/org/hibernate/test/discriminator/DiscriminatorTest.java	2007-10-31 00:13:38 UTC (rev 14159)
@@ -10,7 +10,9 @@
 import org.hibernate.Hibernate;
 import org.hibernate.Session;
 import org.hibernate.Transaction;
+import org.hibernate.proxy.HibernateProxy;
 import org.hibernate.criterion.Property;
+import org.hibernate.criterion.Restrictions;
 import org.hibernate.junit.functional.FunctionalTestCase;
 import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
 
@@ -171,6 +173,82 @@
 		s.close();
 	}
 
+	public void testLoadSuperclassProxyPolymorphicAccess() {
+		Session s = openSession();
+		s.beginTransaction();
+		Employee e = new Employee();
+		e.setName( "Steve" );
+		e.setSex( 'M' );
+		e.setTitle( "grand poobah" );
+		s.save( e );
+		s.getTransaction().commit();
+		s.close();
 
+		s = openSession();
+		s.beginTransaction();
+		// load the superclass proxy.
+		Person pLoad = ( Person ) s.load( Person.class, new Long( e.getId() ) );
+		assertTrue( pLoad instanceof HibernateProxy);
+		Person pGet = ( Person ) s.get( Person.class, new Long( e.getId() ));
+		Person pQuery = ( Person ) s.createQuery( "from Person where id = :id" )
+				.setLong( "id", e.getId() )
+				.uniqueResult();
+		Person pCriteria = ( Person ) s.createCriteria( Person.class )
+				.add( Restrictions.idEq( new Long( e.getId() ) ) )
+				.uniqueResult();
+		// assert that executing the queries polymorphically returns the same proxy
+		assertSame( pLoad, pGet );
+		assertSame( pLoad, pQuery );
+		assertSame( pLoad, pCriteria );
+
+		// assert that the proxy is not an instance of Employee
+		assertFalse( pLoad instanceof Employee );
+
+		s.getTransaction().commit();
+		s.close();
+
+		s = openSession();
+		s.beginTransaction();
+		s.delete( e );
+		s.getTransaction().commit();
+		s.close();
+	}
+
+	public void testLoadSuperclassProxyEvictPolymorphicAccess() {
+		Session s = openSession();
+		s.beginTransaction();
+		Employee e = new Employee();
+		e.setName( "Steve" );
+		e.setSex( 'M' );
+		e.setTitle( "grand poobah" );
+		s.save( e );
+		s.getTransaction().commit();
+		s.close();
+
+		s = openSession();
+		s.beginTransaction();
+		// load the superclass proxy.
+		Person pLoad = ( Person ) s.load( Person.class, new Long( e.getId() ) );
+		assertTrue( pLoad instanceof HibernateProxy);
+		// evict the proxy
+		s.evict( pLoad );
+		Employee pGet = ( Employee ) s.get( Person.class, new Long( e.getId() ));
+		Employee pQuery = ( Employee ) s.createQuery( "from Person where id = :id" )
+				.setLong( "id", e.getId() )
+				.uniqueResult();
+		Employee pCriteria = ( Employee ) s.createCriteria( Person.class )
+				.add( Restrictions.idEq( new Long( e.getId() ) ) )
+				.uniqueResult();
+		// assert that executing the queries polymorphically returns the same Employee instance
+		assertSame( pGet, pQuery );
+		assertSame( pGet, pCriteria );
+		s.getTransaction().commit();
+		s.close();
+
+		s = openSession();
+		s.beginTransaction();
+		s.delete( e );
+		s.getTransaction().commit();
+		s.close();
+	}
 }
-




More information about the hibernate-commits mailing list