[hibernate-commits] Hibernate SVN: r10941 - in trunk/Hibernate3: src/org/hibernate/hql/ast/tree test/org/hibernate/test/hql

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Dec 7 08:49:25 EST 2006


Author: steve.ebersole at jboss.com
Date: 2006-12-07 08:49:22 -0500 (Thu, 07 Dec 2006)
New Revision: 10941

Modified:
   trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
   trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
   trunk/Hibernate3/test/org/hibernate/test/hql/CrazyIdFieldNames.hbm.xml
   trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
Log:
test failures - shallow + implicit joins

Modified: trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java	2006-12-07 12:59:25 UTC (rev 10940)
+++ trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java	2006-12-07 13:49:22 UTC (rev 10941)
@@ -25,16 +25,18 @@
 /**
  * Represents a reference to a property or alias expression.  This should duplicate the relevant behaviors in
  * PathExpressionParser.
- * <hr>
- * User: josh<br>
- * Date: Dec 16, 2003<br>
- * Time: 8:03:09 AM
+ *
+ * @author Joshua Davis
  */
 public class DotNode extends FromReferenceNode implements DisplayableNode, SelectExpression {
 
-	/**
-	 * A logger for this class.
-	 */
+	///////////////////////////////////////////////////////////////////////////
+	// USED ONLY FOR REGRESSION TESTING!!!!
+	///////////////////////////////////////////////////////////////////////////
+	public static boolean useThetaStyleImplicitJoins = false;
+	public static boolean REGRESSION_STYLE_JOIN_SUPPRESSION = false;
+	///////////////////////////////////////////////////////////////////////////
+
 	private static final Log log = LogFactory.getLog( DotNode.class );
 
 	private static final int DEREF_UNKNOWN = 0;
@@ -285,19 +287,26 @@
 
 	private void dereferenceEntity(EntityType entityType, boolean implicitJoin, String classAlias, boolean generateJoin, AST parent) throws SemanticException {
 		checkForCorrelatedSubquery( "dereferenceEntity" );
-		// three general cases we check here:
+		// three general cases we check here as to whether to render a physical SQL join:
 		// 1) is our parent a DotNode as well?  If so, our property reference is
 		// 		being further de-referenced...
 		// 2) is this a DML statement
 		// 3) we were asked to generate any needed joins (generateJoins==true) *OR*
-		//		the current parser state indicates to use an INNER JOIN for implicit joins
+		//		we are currently processing a select or from clause
+		// (an additional check is the REGRESSION_STYLE_JOIN_SUPPRESSION check solely intended for the test suite)
 		//
-		// The "implicit join" portion of the second condition was done to account for
-		// situations like HHH-2257 to make sure that iterate() and list() return
-		// consistent results.  Previously the join would be skipped on "shallow queries"
-		// (aka, iterate()) for performance reasons, but that can lead to incorrect
-		// results since INNER JOINs do place extra restrications on the returned
-		// results.
+		// The REGRESSION_STYLE_JOIN_SUPPRESSION is an additional check
+		// intended solely for use within the test suite.  This forces the
+		// implicit join resolution to behave more like the classic parser.
+		// The underlying issue is that classic translator is simply wrong
+		// about its decisions on whether or not to render an implicit join
+		// into a physical SQL join in a lot of cases.  The piece it generally
+		// tends to miss is that INNER joins effect the results by further
+		// restricting the data set!  A particular manifestation of this is
+		// the fact that the classic translator will skip the physical join
+		// for ToOne implicit joins *if the query is shallow*; the result
+		// being that Query.list() and Query.iterate() could return
+		// different number of results!
 		DotNode parentAsDotNode = null;
 		String property = propertyName;
 		final boolean joinIsNeeded;
@@ -313,10 +322,12 @@
 		else if ( ! getWalker().isSelectStatement() ) {
 			joinIsNeeded = false;
 		}
+		else if ( REGRESSION_STYLE_JOIN_SUPPRESSION ) {
+			// this is the regression style determination which matches the logic of the classic translator
+			joinIsNeeded = generateJoin && ( !getWalker().isInSelect() || !getWalker().isShallowQuery() );
+		}
 		else {
-			// otherwise we need to generate the join if we were asked to, or
-			// if the current implicit join type is INNER JOINs
-			joinIsNeeded = generateJoin || getWalker().getImpliedJoinType() == JoinFragment.INNER_JOIN;
+			joinIsNeeded = generateJoin || ( getWalker().isInSelect() || getWalker().isInFrom() );
 		}
 
 		if ( joinIsNeeded ) {
@@ -623,11 +634,6 @@
 		}
 	}
 
-	/**
-	 * Used ONLY for regression testing!
-	 */
-	public static boolean useThetaStyleImplicitJoins = false;
-
 	public void setResolvedConstant(String text) {
 		path = text;
 		dereferenceType = DEREF_JAVA_CONSTANT;

Modified: trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java	2006-12-07 12:59:25 UTC (rev 10940)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java	2006-12-07 13:49:22 UTC (rev 10941)
@@ -77,6 +77,7 @@
 				"hql/Animal.hbm.xml",
 				"hql/FooBarCopy.hbm.xml",
 				"hql/SimpleEntityWithAssociation.hbm.xml",
+				"hql/CrazyIdFieldNames.hbm.xml",
 				"batchfetch/ProductLine.hbm.xml",
 				"cid/Customer.hbm.xml",
 				"cid/Order.hbm.xml",
@@ -94,6 +95,41 @@
 		cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
 	}
 
+	public void testCrazyIdFieldNames() {
+		MoreCrazyIdFieldNameStuffEntity top = new MoreCrazyIdFieldNameStuffEntity( "top" );
+		HeresAnotherCrazyIdFieldName next = new HeresAnotherCrazyIdFieldName( "next" );
+		top.setHeresAnotherCrazyIdFieldName( next );
+		MoreCrazyIdFieldNameStuffEntity other = new MoreCrazyIdFieldNameStuffEntity( "other" );
+		Session s = openSession();
+		s.beginTransaction();
+		s.save( next );
+		s.save( top );
+		s.save( other );
+		s.flush();
+
+		List results = s.createQuery( "select e.heresAnotherCrazyIdFieldName from MoreCrazyIdFieldNameStuffEntity e where e.heresAnotherCrazyIdFieldName is not null" ).list();
+		assertEquals( 1, results.size() );
+		Object result = results.get( 0 );
+		assertClassAssignability( HeresAnotherCrazyIdFieldName.class, result.getClass() );
+		assertSame( next, result );
+
+		results = s.createQuery( "select e.heresAnotherCrazyIdFieldName.heresAnotherCrazyIdFieldName from MoreCrazyIdFieldNameStuffEntity e where e.heresAnotherCrazyIdFieldName is not null" ).list();
+		assertEquals( 1, results.size() );
+		result = results.get( 0 );
+		assertClassAssignability( Long.class, result.getClass() );
+		assertEquals( next.getHeresAnotherCrazyIdFieldName(), result );
+
+		results = s.createQuery( "select e.heresAnotherCrazyIdFieldName from MoreCrazyIdFieldNameStuffEntity e" ).list();
+		assertEquals( 1, results.size() );
+		Iterator itr = s.createQuery( "select e.heresAnotherCrazyIdFieldName from MoreCrazyIdFieldNameStuffEntity e" ).iterate();
+		assertTrue( itr.hasNext() ); itr.next(); assertFalse( itr.hasNext() );
+
+		s.delete( top );
+		s.delete( next );
+		s.getTransaction().commit();
+		s.close();
+	}
+
 	public void testImplicitJoinsInDifferentClauses() {
 		// HHH-2257 :
 		// both the classic and ast translators output the same syntactically valid sql

Modified: trunk/Hibernate3/test/org/hibernate/test/hql/CrazyIdFieldNames.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/CrazyIdFieldNames.hbm.xml	2006-12-07 12:59:25 UTC (rev 10940)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/CrazyIdFieldNames.hbm.xml	2006-12-07 13:49:22 UTC (rev 10941)
@@ -4,16 +4,16 @@
 
 <hibernate-mapping package="org.hibernate.test.hql">
 
-    <class name="HeresAnotherCrazyIdFieldName">
+    <class name="HeresAnotherCrazyIdFieldName" table="CRAZY_ID_NODE">
         <id name="heresAnotherCrazyIdFieldName" column="ID" type="long">
-            <generator class="native"/>
+            <generator class="increment"/>
         </id>
         <property name="name" type="string"/>
     </class>
 
-    <class name="MoreCrazyIdFieldNameStuffEntity">
+    <class name="MoreCrazyIdFieldNameStuffEntity" table="CRAZY_ID_TOP">
         <id name="moreCrazyIdFieldNameStuffEntity" column="ID" type="long">
-            <generator class="native"/>
+            <generator class="increment"/>
         </id>
         <property name="name" type="string" />
         <many-to-one name="heresAnotherCrazyIdFieldName" class="HeresAnotherCrazyIdFieldName"/>

Modified: trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java	2006-12-07 12:59:25 UTC (rev 10940)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java	2006-12-07 13:49:22 UTC (rev 10941)
@@ -43,13 +43,24 @@
 
 	public HQLTest(String x) {
 		super( x );
-		SelectClause.VERSION2_SQL = true;
 	}
 
 	protected boolean dropAfterFailure() {
 		return false;
 	}
 
+	protected void setUp() throws Exception {
+		super.setUp();
+		SelectClause.VERSION2_SQL = true;
+		DotNode.REGRESSION_STYLE_JOIN_SUPPRESSION = true;
+	}
+
+	protected void tearDown() throws Exception {
+		SelectClause.VERSION2_SQL = false;
+		DotNode.REGRESSION_STYLE_JOIN_SUPPRESSION = false;
+		super.tearDown();
+	}
+
 	//FAILING TESTS:
 
 	public void testSubComponentReferences() {




More information about the hibernate-commits mailing list