[hibernate-commits] Hibernate SVN: r11373 - trunk/Hibernate3/test/org/hibernate/test/hql.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Mar 29 15:09:07 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-03-29 15:09:07 -0400 (Thu, 29 Mar 2007)
New Revision: 11373

Modified:
   trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
HHH-2534 : better improper HQL collection-dereference error message

Modified: trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java	2007-03-29 19:08:53 UTC (rev 11372)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java	2007-03-29 19:09:07 UTC (rev 11373)
@@ -50,6 +50,9 @@
 import org.hibernate.type.Type;
 import org.hibernate.util.StringHelper;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * Tests the integration of the new AST parser into the loading of query results using
  * the Hibernate persisters and loaders.
@@ -62,6 +65,8 @@
  */
 public class ASTParserLoadingTest extends FunctionalTestCase {
 
+	private static final Log log = LogFactory.getLog( ASTParserLoadingTest.class );
+
 	private List createdAnimalIds = new ArrayList();
 
 	public ASTParserLoadingTest(String name) {
@@ -96,6 +101,52 @@
 		return new FunctionalTestClassTestSuite( ASTParserLoadingTest.class );
 	}
 
+	public void testInvalidCollectionDereferencesFail() {
+		Session s = openSession();
+		s.beginTransaction();
+
+		// control group...
+		s.createQuery( "from Animal a join a.offspring o where o.description = 'xyz'" ).list();
+		s.createQuery( "from Animal a join a.offspring o where o.father.description = 'xyz'" ).list();
+		s.createQuery( "from Animal a join a.offspring o order by o.description" ).list();
+		s.createQuery( "from Animal a join a.offspring o order by o.father.description" ).list();
+
+		try {
+			s.createQuery( "from Animal a where a.offspring.description = 'xyz'" ).list();
+			fail( "illegal collection dereference semantic did not cause failure" );
+		}
+		catch( QueryException qe ) {
+			log.trace( "expected failure...", qe );
+		}
+
+		try {
+			s.createQuery( "from Animal a where a.offspring.father.description = 'xyz'" ).list();
+			fail( "illegal collection dereference semantic did not cause failure" );
+		}
+		catch( QueryException qe ) {
+			log.trace( "expected failure...", qe );
+		}
+
+		try {
+			s.createQuery( "from Animal a order by a.offspring.description" ).list();
+			fail( "illegal collection dereference semantic did not cause failure" );
+		}
+		catch( QueryException qe ) {
+			log.trace( "expected failure...", qe );
+		}
+
+		try {
+			s.createQuery( "from Animal a order by a.offspring.father.description" ).list();
+			fail( "illegal collection dereference semantic did not cause failure" );
+		}
+		catch( QueryException qe ) {
+			log.trace( "expected failure...", qe );
+		}
+
+		s.getTransaction().commit();
+		s.close();
+	}
+
 	/**
 	 * Copied from {@link HQLTest#testConcatenation}
 	 */




More information about the hibernate-commits mailing list