Skip to content

Commit 5ac46eb

Browse files
committed
HHH-11383 - Removed InvalidWithClauseException check when join alias != table alias
1 parent 327d0a9 commit 5ac46eb

File tree

2 files changed

+16
-45
lines changed

2 files changed

+16
-45
lines changed

hibernate-core/src/main/java/org/hibernate/hql/internal/ast/HqlSqlWalker.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,12 @@ public void visit(AST node) {
563563
// needed because currently persister is the one that
564564
// creates and renders the join fragments for inheritance
565565
// hierarchies...
566-
if ( !joinAlias.equals( referencedFromElement.getTableAlias() ) ) {
567-
throw new InvalidWithClauseException(
568-
"with clause can only reference columns in the driving table",
569-
queryTranslatorImpl.getQueryString()
570-
);
571-
}
566+
// if ( !joinAlias.equals( referencedFromElement.getTableAlias() ) ) {
567+
// throw new InvalidWithClauseException(
568+
// "with clause can only reference columns in the driving table",
569+
// queryTranslatorImpl.getQueryString()
570+
// );
571+
// }
572572
}
573573
}
574574
else if ( node instanceof ParameterNode ) {

hibernate-core/src/test/java/org/hibernate/test/hql/WithClauseTest.java

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package org.hibernate.test.hql;
88

99
import java.util.ArrayList;
10-
import java.util.Collections;
1110
import java.util.HashMap;
1211
import java.util.List;
1312

@@ -17,7 +16,6 @@
1716
import org.hibernate.Session;
1817
import org.hibernate.Transaction;
1918
import org.hibernate.cfg.AvailableSettings;
20-
import org.hibernate.hql.internal.ast.InvalidWithClauseException;
2119

2220
import org.hibernate.testing.TestForIssue;
2321
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@@ -66,43 +64,6 @@ public void testWithClauseFailsWithFetch() {
6664
data.cleanup();
6765
}
6866

69-
@Test
70-
public void testInvalidWithSemantics() {
71-
Session s = openSession();
72-
Transaction txn = s.beginTransaction();
73-
74-
try {
75-
// PROBLEM : f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
76-
// alias relates to the Human.friends collection which the aonther Human entity. The issue
77-
// here is the way JoinSequence and Joinable (the persister) interact to generate the
78-
// joins relating to the sublcass/superclass tables
79-
s.createQuery( "from Human h inner join h.friends as f with f.bodyWeight < :someLimit" )
80-
.setDouble( "someLimit", 1 )
81-
.list();
82-
fail( "failure expected" );
83-
}
84-
catch (IllegalArgumentException e) {
85-
assertTyping( QueryException.class, e.getCause() );
86-
}
87-
catch( InvalidWithClauseException expected ) {
88-
}
89-
90-
try {
91-
s.createQuery( "from Human h inner join h.offspring o with o.mother.father = :cousin" )
92-
.setEntity( "cousin", s.load( Human.class, new Long(123) ) )
93-
.list();
94-
fail( "failure expected" );
95-
}
96-
catch (IllegalArgumentException e) {
97-
assertTyping( QueryException.class, e.getCause() );
98-
}
99-
catch( InvalidWithClauseException expected ) {
100-
}
101-
102-
txn.commit();
103-
s.close();
104-
}
105-
10667
@Test
10768
public void testWithClause() {
10869
TestData data = new TestData();
@@ -123,6 +84,11 @@ public void testWithClause() {
12384
.list();
12485
assertTrue( "ad-hoc on did not take effect", list.isEmpty() );
12586

87+
list = s.createQuery( "from Human h inner join h.friends f with f.bodyWeight < :someLimit" )
88+
.setDouble( "someLimit", 25 )
89+
.list();
90+
assertTrue( "ad-hoc on did take effect", !list.isEmpty() );
91+
12692
// many-to-many
12793
list = s.createQuery( "from Human h inner join h.friends as f with f.nickName like 'bubba'" )
12894
.list();
@@ -133,6 +99,11 @@ public void testWithClause() {
13399
.list();
134100
assertTrue( "ad-hoc on did not take effect", list.isEmpty() );
135101

102+
list = s.createQuery( "from Human h inner join h.offspring o with o.mother.father = :cousin" )
103+
.setEntity( "cousin", s.load( Human.class, Long.valueOf( "123" ) ) )
104+
.list();
105+
assertTrue( "ad-hoc did take effect", list.isEmpty() );
106+
136107
txn.commit();
137108
s.close();
138109

0 commit comments

Comments
 (0)