HHH-9342 - HQL "x member of treat(y as Type).collections" fails to parse
This commit is contained in:
parent
6ed765ede3
commit
a35abf43e9
|
@ -593,7 +593,7 @@ relationalExpression
|
|||
#l.setText( (n == null) ? "like" : "not like");
|
||||
}
|
||||
concatenation likeEscape)
|
||||
| (MEMBER! (OF!)? p:path! {
|
||||
| (MEMBER! (OF!)? p:memberOfPath! {
|
||||
processMemberOf(n,#p,currentAST);
|
||||
} ) )
|
||||
)
|
||||
|
@ -612,6 +612,14 @@ betweenList
|
|||
: concatenation AND! concatenation
|
||||
;
|
||||
|
||||
memberOfPath
|
||||
// JPA says this is a `collection_valued_path_expression` which is essentially either:
|
||||
// 1) a treated path followed by a collection-valued attribute reference
|
||||
// 2) a path
|
||||
: { validateSoftKeyword("treat") && LA(2) == OPEN }? i:IDENT! OPEN! p:path AS! a:path! CLOSE! ( DOT^ path )
|
||||
| path
|
||||
;
|
||||
|
||||
//level 4 - string concatenation
|
||||
concatenation
|
||||
: additiveExpression
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.hql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests the "treat" keyword in HQL.
|
||||
*
|
||||
* @author Etienne Miret
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @see org.hibernate.test.jpa.ql.TreatKeywordTest
|
||||
*/
|
||||
public class TreatKeywordTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "hql/Animal.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9342" )
|
||||
public void memberOfTreatTest() {
|
||||
// prepare test data
|
||||
Session s = openSession();
|
||||
s.getTransaction().begin();
|
||||
|
||||
Human owner = new Human();
|
||||
s.persist( owner );
|
||||
|
||||
Dog wildDog = new Dog();
|
||||
s.persist( wildDog );
|
||||
|
||||
Dog petDog = new Dog();
|
||||
petDog.setOwner( owner );
|
||||
s.persist( petDog );
|
||||
|
||||
Cat petCat = new Cat();
|
||||
petCat.setOwner( owner );
|
||||
s.persist( petCat );
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
|
||||
// perform test
|
||||
s = openSession();
|
||||
s.getTransaction().begin();
|
||||
Query q = s.createQuery(
|
||||
"select pet" +
|
||||
" from Animal pet, Animal owner" +
|
||||
" where pet member of treat (owner as Human).pets"
|
||||
);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Animal> results = q.list();
|
||||
assertEquals( 2, results.size() );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
|
||||
// clean up test data
|
||||
s = openSession();
|
||||
s.getTransaction().begin();
|
||||
s.delete( petCat );
|
||||
s.delete( petDog );
|
||||
s.delete( wildDog );
|
||||
s.delete( owner );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue