HHH-11383 - Removed InvalidWithClauseException check when join alias != table alias

(cherry picked from commit 5ac46eb703)
This commit is contained in:
Chris Cranford 2017-01-16 16:58:04 -05:00 committed by Gail Badner
parent 2523f0abbb
commit 63b37251cb
2 changed files with 16 additions and 38 deletions

View File

@ -568,12 +568,12 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
// needed because currently persister is the one that
// creates and renders the join fragments for inheritance
// hierarchies...
if ( !joinAlias.equals( referencedFromElement.getTableAlias() ) ) {
throw new InvalidWithClauseException(
"with clause can only reference columns in the driving table",
queryTranslatorImpl.getQueryString()
);
}
// if ( !joinAlias.equals( referencedFromElement.getTableAlias() ) ) {
// throw new InvalidWithClauseException(
// "with clause can only reference columns in the driving table",
// queryTranslatorImpl.getQueryString()
// );
// }
}
}
else if ( node instanceof ParameterNode ) {

View File

@ -18,7 +18,6 @@ import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.hql.internal.ast.InvalidWithClauseException;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
@ -57,37 +56,6 @@ public class WithClauseTest extends BaseCoreFunctionalTestCase {
data.cleanup();
}
@Test
public void testInvalidWithSemantics() {
Session s = openSession();
Transaction txn = s.beginTransaction();
try {
// PROBLEM : f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
// alias relates to the Human.friends collection which the aonther Human entity. The issue
// here is the way JoinSequence and Joinable (the persister) interact to generate the
// joins relating to the sublcass/superclass tables
s.createQuery( "from Human h inner join h.friends as f with f.bodyWeight < :someLimit" )
.setDouble( "someLimit", 1 )
.list();
fail( "failure expected" );
}
catch( InvalidWithClauseException expected ) {
}
try {
s.createQuery( "from Human h inner join h.offspring o with o.mother.father = :cousin" )
.setEntity( "cousin", s.load( Human.class, new Long(123) ) )
.list();
fail( "failure expected" );
}
catch( InvalidWithClauseException expected ) {
}
txn.commit();
s.close();
}
@Test
public void testWithClause() {
TestData data = new TestData();
@ -108,6 +76,11 @@ public class WithClauseTest extends BaseCoreFunctionalTestCase {
.list();
assertTrue( "ad-hoc on did not take effect", list.isEmpty() );
list = s.createQuery( "from Human h inner join h.friends f with f.bodyWeight < :someLimit" )
.setDouble( "someLimit", 25 )
.list();
assertTrue( "ad-hoc on did take effect", !list.isEmpty() );
// many-to-many
list = s.createQuery( "from Human h inner join h.friends as f with f.nickName like 'bubba'" )
.list();
@ -118,6 +91,11 @@ public class WithClauseTest extends BaseCoreFunctionalTestCase {
.list();
assertTrue( "ad-hoc on did not take effect", list.isEmpty() );
list = s.createQuery( "from Human h inner join h.offspring o with o.mother.father = :cousin" )
.setEntity( "cousin", s.load( Human.class, Long.valueOf( "123" ) ) )
.list();
assertTrue( "ad-hoc did take effect", list.isEmpty() );
txn.commit();
s.close();