Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

HHH-5209 - org.hibernate.hql.ast.QuerySyntaxException when running a …

…JPQL query with a MEMBER OF on an @ElementCollection
  • Loading branch information...
commit 199ee7860ebec5adbcb419d454634f47e24ff8c0 1 parent 4152ff6
Steve Ebersole authored
14  hibernate-core/src/main/java/org/hibernate/hql/internal/ast/HqlParser.java
@@ -383,11 +383,15 @@ public void handleDotIdent() throws TokenStreamException {
383 383
 
384 384
 	@Override
385 385
     public void processMemberOf(Token n, AST p, ASTPair currentAST) {
386  
-		AST inAst = n == null ? astFactory.create( IN, "in" ) : astFactory.create( NOT_IN, "not in" );
387  
-		astFactory.makeASTRoot( currentAST, inAst );
388  
-		AST ast = createSubquery( p );
389  
-		ast = ASTUtil.createParent( astFactory, IN_LIST, "inList", ast );
390  
-		inAst.addChild( ast );
  386
+		// convert MEMBER OF to the equivalent IN ELEMENTS structure...
  387
+		AST inNode = n == null ? astFactory.create( IN, "in" ) : astFactory.create( NOT_IN, "not in" );
  388
+		astFactory.makeASTRoot( currentAST, inNode );
  389
+
  390
+		AST inListNode = astFactory.create( IN_LIST, "inList" );
  391
+		inNode.addChild( inListNode );
  392
+		AST elementsNode = astFactory.create( ELEMENTS, "elements" );
  393
+		inListNode.addChild( elementsNode );
  394
+		elementsNode.addChild( p );
391 395
 	}
392 396
 
393 397
 	static public void panic() {
57  ...e-core/src/test/java/org/hibernate/test/annotations/collectionelement/EntityWithAnElementCollection.java
... ...
@@ -0,0 +1,57 @@
  1
+/*
  2
+ * Hibernate, Relational Persistence for Idiomatic Java
  3
+ *
  4
+ * Copyright (c) 2012, Red Hat Inc. or third-party contributors as
  5
+ * indicated by the @author tags or express copyright attribution
  6
+ * statements applied by the authors.  All third-party contributions are
  7
+ * distributed under license by Red Hat Inc.
  8
+ *
  9
+ * This copyrighted material is made available to anyone wishing to use, modify,
  10
+ * copy, or redistribute it subject to the terms and conditions of the GNU
  11
+ * Lesser General Public License, as published by the Free Software Foundation.
  12
+ *
  13
+ * This program is distributed in the hope that it will be useful,
  14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
  16
+ * for more details.
  17
+ *
  18
+ * You should have received a copy of the GNU Lesser General Public License
  19
+ * along with this distribution; if not, write to:
  20
+ * Free Software Foundation, Inc.
  21
+ * 51 Franklin Street, Fifth Floor
  22
+ * Boston, MA  02110-1301  USA
  23
+ */
  24
+package org.hibernate.test.annotations.collectionelement;
  25
+
  26
+import javax.persistence.ElementCollection;
  27
+import javax.persistence.Entity;
  28
+import javax.persistence.Id;
  29
+import java.util.HashSet;
  30
+import java.util.Set;
  31
+
  32
+/**
  33
+ * @author Steve Ebersole
  34
+ */
  35
+@Entity
  36
+public class EntityWithAnElementCollection {
  37
+	private Long id;
  38
+	private Set<String> someStrings = new HashSet<String>();
  39
+
  40
+	@Id
  41
+	public Long getId() {
  42
+		return id;
  43
+	}
  44
+
  45
+	public void setId(Long id) {
  46
+		this.id = id;
  47
+	}
  48
+
  49
+	@ElementCollection
  50
+	public Set<String> getSomeStrings() {
  51
+		return someStrings;
  52
+	}
  53
+
  54
+	public void setSomeStrings(Set<String> someStrings) {
  55
+		this.someStrings = someStrings;
  56
+	}
  57
+}
51  hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/QueryTest.java
... ...
@@ -0,0 +1,51 @@
  1
+/*
  2
+ * Hibernate, Relational Persistence for Idiomatic Java
  3
+ *
  4
+ * Copyright (c) 2012, Red Hat Inc. or third-party contributors as
  5
+ * indicated by the @author tags or express copyright attribution
  6
+ * statements applied by the authors.  All third-party contributions are
  7
+ * distributed under license by Red Hat Inc.
  8
+ *
  9
+ * This copyrighted material is made available to anyone wishing to use, modify,
  10
+ * copy, or redistribute it subject to the terms and conditions of the GNU
  11
+ * Lesser General Public License, as published by the Free Software Foundation.
  12
+ *
  13
+ * This program is distributed in the hope that it will be useful,
  14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
  16
+ * for more details.
  17
+ *
  18
+ * You should have received a copy of the GNU Lesser General Public License
  19
+ * along with this distribution; if not, write to:
  20
+ * Free Software Foundation, Inc.
  21
+ * 51 Franklin Street, Fifth Floor
  22
+ * Boston, MA  02110-1301  USA
  23
+ */
  24
+package org.hibernate.test.annotations.collectionelement;
  25
+
  26
+import org.hibernate.Session;
  27
+
  28
+import org.junit.Test;
  29
+
  30
+import org.hibernate.testing.TestForIssue;
  31
+import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
  32
+
  33
+/**
  34
+ * @author Steve Ebersole
  35
+ */
  36
+public class QueryTest extends BaseCoreFunctionalTestCase {
  37
+	@Override
  38
+	protected Class<?>[] getAnnotatedClasses() {
  39
+		return new Class[] { EntityWithAnElementCollection.class };
  40
+	}
  41
+
  42
+	@Test
  43
+	@TestForIssue( jiraKey = "HHH-5209" )
  44
+	public void testMemberOfSyntax() {
  45
+		// performs syntax checking of the MEMBER OF predicate against a basic collection
  46
+		Session s = openSession();
  47
+//		s.createQuery( "from EntityWithAnElementCollection e where 'abc' in elements( e.someStrings )" ).list();
  48
+		s.createQuery( "from EntityWithAnElementCollection e where 'abc' member of e.someStrings" ).list();
  49
+		s.close();
  50
+	}
  51
+}

0 notes on commit 199ee78

Please sign in to comment.
Something went wrong with that request. Please try again.