[hibernate-commits] Hibernate SVN: r14200 - in core/trunk: testsuite/src/test/java/org/hibernate/test/hql and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Nov 16 15:25:59 EST 2007


Author: steve.ebersole at jboss.com
Date: 2007-11-16 15:25:59 -0500 (Fri, 16 Nov 2007)
New Revision: 14200

Modified:
   core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java
   core/trunk/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java
Log:
HHH-2833 : insert-select query fails with NPE when select includes join

Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java	2007-11-16 12:43:51 UTC (rev 14199)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java	2007-11-16 20:25:59 UTC (rev 14200)
@@ -336,7 +336,8 @@
 			joinIsNeeded = generateJoin && !isReferenceToPrimaryKey( parentAsDotNode.propertyName, entityType );
 		}
 		else if ( ! getWalker().isSelectStatement() ) {
-			joinIsNeeded = false;
+			// in non-select queries, the only time we should need to join is if we are in a subquery from clause
+			joinIsNeeded = getWalker().getCurrentStatementType() == SqlTokenTypes.SELECT && getWalker().isInFrom();
 		}
 		else if ( REGRESSION_STYLE_JOIN_SUPPRESSION ) {
 			// this is the regression style determination which matches the logic of the classic translator

Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java	2007-11-16 12:43:51 UTC (rev 14199)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java	2007-11-16 20:25:59 UTC (rev 14200)
@@ -451,6 +451,18 @@
 		s.close();
 	}
 
+	public void testInsertWithSelectListUsingJoins() {
+		// this is just checking parsing and syntax...
+		Session s = openSession();
+		s.beginTransaction();
+		s.createQuery( "insert into Animal (description, bodyWeight) select h.description, h.bodyWeight from Human h where h.mother.mother is not null" ).executeUpdate();
+		s.createQuery( "insert into Animal (description, bodyWeight) select h.description, h.bodyWeight from Human h join h.mother m where m.mother is not null" ).executeUpdate();
+		s.createQuery( "delete from Animal" ).executeUpdate();
+		s.getTransaction().commit();
+		s.close();
+	}
+
+
 	// UPDATES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 	public void testIncorrectSyntax() {




More information about the hibernate-commits mailing list