]
Emmanuel Bernard commented on HHH-5713:
---------------------------------------
Looking at the JPA 2 grammar, this is legal.
In our AST, it seems the member of is replaced by a inList and then boom :)
Member of doesn't work with a @ElementCollection of String
----------------------------------------------------------
Key: HHH-5713
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5713
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.6.0
Reporter: Antonio Goncalves
Attachments: JavaEE6Devoxx.zip
Also see
https://forum.hibernate.org/viewtopic.php?f=1&t=1007606&p=2437844
I have the following @Entity :
{code}
public class Book {
@Id @GeneratedValue
private Long id;
private String title;
private Float price;
private String isbn;
@ElementCollection
@CollectionTable(name = "tags")
private List<String> tags = new ArrayList<String>();
{code}
I use {{@ElementCollection}} to have a list of strings (tags you can add to books). I
want to find all the books that have a tag equals to "scifi", so I wrote the
following named query :
{code}
SELECT b FROM Book b WHERE 'scifi' member of b.tags
{code}
But here is what I get (with log level at debug) :
{code}
10:53:14,512 DEBUG QueryTranslatorImpl:272 - parse() - HQL: SELECT b FROM
org.beginningee6.tutorial.Book b WHERE 'scifi' member of b.tags
10:53:14,527 DEBUG AST:291 - --- HQL AST ---
\-[QUERY] Node: 'query'
+-[SELECT_FROM] Node: 'SELECT_FROM'
| +-[FROM] Node: 'FROM'
| | \-[RANGE] Node: 'RANGE'
| | +-[DOT] Node: '.'
| | | +-[DOT] Node: '.'
| | | | +-[DOT] Node: '.'
| | | | | +-[IDENT] Node: 'org'
| | | | | \-[IDENT] Node: 'beginningee6'
| | | | \-[IDENT] Node: 'tutorial'
| | | \-[IDENT] Node: 'Book'
| | \-[ALIAS] Node: 'b'
| \-[SELECT] Node: 'SELECT'
| \-[IDENT] Node: 'b'
\-[WHERE] Node: 'WHERE'
\-[IN] Node: 'in'
+-[QUOTED_STRING] Node: ''scifi''
\-[IN_LIST] Node: 'inList'
\-[QUERY] Node: 'QUERY'
\-[SELECT_FROM] Node: 'SELECT_FROM'
\-[FROM] Node: 'from'
\-[RANGE] Node: 'RANGE'
\-[DOT] Node: '.'
+-[IDENT] Node: 'b'
\-[IDENT] Node: 'tags'
10:53:14,527 DEBUG ErrorCounter:91 - throwQueryException() : no errors
10:53:14,527 DEBUG HqlSqlBaseWalker:111 - select << begin [level=1,
statement=select]
10:53:14,527 DEBUG FromElement:157 - FromClause{level=1} :
org.beginningee6.tutorial.Book (b) -> book0_
10:53:14,527 DEBUG FromReferenceNode:74 - Resolved : b -> book0_.id
10:53:14,527 DEBUG HqlSqlBaseWalker:111 - select << begin [level=2,
statement=select]
10:53:14,543 DEBUG FromElementFactory:131 - createFromElementInSubselect() : path =
b.tags
10:53:14,543 DEBUG PathHelper:69 - parsePath() : b.tags -> [ ( . b tags ) ]
10:53:14,543 DEBUG FromReferenceNode:74 - Resolved : b -> book0_.id
10:53:14,543 DEBUG DotNode:613 - getDataType() : tags ->
org.hibernate.type.BagType(org.beginningee6.tutorial.Book.tags)
10:53:14,543 DEBUG FromElement:157 - FromClause{level=2} : null (no alias) -> tags1_
10:53:14,543 DEBUG FromClause:368 - addCollectionJoinFromElementByPath() : b.tags ->
tags
10:53:14,543 DEBUG DotNode:306 - dereferenceCollection() : Created new FROM element for
b.tags : tags tags1_
10:53:14,543 DEBUG FromReferenceNode:74 - Resolved : b.tags -> .
10:53:14,543 DEBUG FromElementFactory:164 - createFromElementInSubselect() : b.tags ->
tags tags1_
10:53:14,543 DEBUG HqlSqlBaseWalker:117 - select : finishing up [level=2,
statement=select]
10:53:14,543 DEBUG HqlSqlWalker:620 - processQuery() : ( SELECT ( FromClause{level=2}
tags tags1_ ) )
10:53:14,543 DEBUG HqlSqlWalker:863 - Derived SELECT clause created.
10:53:14,543 DEBUG SyntheticAndFactory:94 - Using unprocessed WHERE-fragment
[book0_.id=tags1_.Book_id]
10:53:14,543 DEBUG SyntheticAndFactory:125 - Using processed WHERE-fragment
[book0_.id=tags1_.Book_id]
10:53:14,543 DEBUG QueryNode:74 - getWhereClause() : Creating a new WHERE clause...
10:53:14,543 DEBUG HqlSqlBaseWalker:123 - select >> end [level=2,
statement=select]
10:53:14,543 DEBUG HqlSqlBaseWalker:117 - select : finishing up [level=1,
statement=select]
10:53:14,543 DEBUG HqlSqlWalker:620 - processQuery() : ( SELECT ( {select clause}
book0_.id ) ( FromClause{level=1} ) ( WHERE ( in 'scifi' ( inList ( SELECT
{derived select clause} ( FromClause{level=2} tags tags1_ ) ( WHERE ( {theta joins}
book0_.id=tags1_.Book_id ) ) ) ) ) ) )
10:53:14,543 DEBUG JoinProcessor:179 - Using FROM fragment [Book book0_]
10:53:14,543 DEBUG HqlSqlBaseWalker:123 - select >> end [level=1,
statement=select]
10:53:14,559 DEBUG AST:258 - --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces (tags,Book)
+-[SELECT_CLAUSE] SelectClause: '{select clause}'
| +-[ALIAS_REF] IdentNode: 'book0_.id as id0_' {alias=b,
className=org.beginningee6.tutorial.Book, tableAlias=book0_}
| \-[SQL_TOKEN] SqlFragment: 'book0_.contentLanguage as contentL2_0_,
book0_.description as descript3_0_, book0_.illustrations as illustra4_0_, book0_.isbn as
isbn0_, book0_.nbOfPage as nbOfPage0_, book0_.price as price0_, book0_.title as
title0_'
+-[FROM] FromClause: 'FROM' FromClause{level=1, fromElementCounter=1,
fromElements=1, fromElementByClassAlias=[b], fromElementByTableAlias=[book0_],
fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
| \-[FROM_FRAGMENT] FromElement: 'Book book0_'
FromElement{explicit,collection join,not a fetch join,fetch non-lazy
properties,classAlias=b,role=null,tableName=Book,tableAlias=book0_,origin=null,columns={,className=org.beginningee6.tutorial.Book}}
\-[WHERE] SqlNode: 'WHERE'
\-[IN] InLogicOperatorNode: 'in'
+-[QUOTED_STRING] LiteralNode: ''scifi''
\-[IN_LIST] SqlNode: 'inList'
\-[SELECT] QueryNode: 'SELECT' querySpaces (tags,Book)
+-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
+-[FROM] FromClause: 'from' FromClause{level=2,
fromElementCounter=0, fromElements=1, fromElementByClassAlias=[],
fromElementByTableAlias=[tags1_], fromElementsByPath=[],
collectionJoinFromElementsByPath=[b.tags], impliedElements=[]}
| \-[FROM_FRAGMENT] ImpliedFromElement: 'tags tags1_'
ImpliedFromElement{implied,collection join,not a fetch join,fetch non-lazy
properties,classAlias=null,role=org.beginningee6.tutorial.Book.tags,tableName={none},tableAlias=tags1_,origin=Book
book0_,columns={,className=null}}
\-[WHERE] SqlNode: 'WHERE'
\-[THETA_JOINS] SqlNode: '{theta joins}'
\-[SQL_TOKEN] SqlFragment: 'book0_.id=tags1_.Book_id'
10:53:14,574 DEBUG ErrorCounter:91 - throwQueryException() : no errors
10:53:14,574 ERROR PARSER:56 - <AST>:0:0: unexpected end of subtree
10:53:14,574 DEBUG ErrorCounter:51 - <AST>:0:0: unexpected end of subtree
<AST>:0:0: unexpected end of subtree
at org.hibernate.hql.antlr.SqlGeneratorBase.selectClause(SqlGeneratorBase.java:523)
at
org.hibernate.hql.antlr.SqlGeneratorBase.selectStatement(SqlGeneratorBase.java:175)
at org.hibernate.hql.antlr.SqlGeneratorBase.parenSelect(SqlGeneratorBase.java:3438)
at org.hibernate.hql.antlr.SqlGeneratorBase.inList(SqlGeneratorBase.java:3315)
at
org.hibernate.hql.antlr.SqlGeneratorBase.exoticComparisonExpression(SqlGeneratorBase.java:3158)
at
org.hibernate.hql.antlr.SqlGeneratorBase.comparisonExpr(SqlGeneratorBase.java:1297)
at org.hibernate.hql.antlr.SqlGeneratorBase.booleanExpr(SqlGeneratorBase.java:910)
at org.hibernate.hql.antlr.SqlGeneratorBase.whereExpr(SqlGeneratorBase.java:768)
at
org.hibernate.hql.antlr.SqlGeneratorBase.selectStatement(SqlGeneratorBase.java:191)
at org.hibernate.hql.antlr.SqlGeneratorBase.statement(SqlGeneratorBase.java:119)
at org.hibernate.hql.ast.QueryTranslatorImpl.generate(QueryTranslatorImpl.java:238)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:205)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
at
org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:547)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:411)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842)
at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)
at
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at org.beginningee6.tutorial.BookTest.initEntityManager(BookTest.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:94)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:192)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
10:53:14,590 ERROR PARSER:56 - <AST>:0:0: expecting "from", found
'<ASTNULL>'
10:53:14,590 DEBUG ErrorCounter:51 - <AST>:0:0: expecting "from", found
'<ASTNULL>'
<AST>:0:0: expecting "from", found '<ASTNULL>'
at antlr.TreeParser.match(TreeParser.java:68)
at org.hibernate.hql.antlr.SqlGeneratorBase.from(SqlGeneratorBase.java:570)
at
org.hibernate.hql.antlr.SqlGeneratorBase.selectStatement(SqlGeneratorBase.java:177)
at org.hibernate.hql.antlr.SqlGeneratorBase.parenSelect(SqlGeneratorBase.java:3438)
at org.hibernate.hql.antlr.SqlGeneratorBase.inList(SqlGeneratorBase.java:3315)
at
org.hibernate.hql.antlr.SqlGeneratorBase.exoticComparisonExpression(SqlGeneratorBase.java:3158)
at
org.hibernate.hql.antlr.SqlGeneratorBase.comparisonExpr(SqlGeneratorBase.java:1297)
at org.hibernate.hql.antlr.SqlGeneratorBase.booleanExpr(SqlGeneratorBase.java:910)
at org.hibernate.hql.antlr.SqlGeneratorBase.whereExpr(SqlGeneratorBase.java:768)
at
org.hibernate.hql.antlr.SqlGeneratorBase.selectStatement(SqlGeneratorBase.java:191)
at org.hibernate.hql.antlr.SqlGeneratorBase.statement(SqlGeneratorBase.java:119)
at org.hibernate.hql.ast.QueryTranslatorImpl.generate(QueryTranslatorImpl.java:238)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:205)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
at
org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:547)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:411)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842)
at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)
at
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at org.beginningee6.tutorial.BookTest.initEntityManager(BookTest.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:94)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:192)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
10:53:14,621 DEBUG QueryTranslatorImpl:241 - HQL: SELECT b FROM
org.beginningee6.tutorial.Book b WHERE 'scifi' member of b.tags
10:53:14,621 DEBUG QueryTranslatorImpl:242 - SQL: select book0_.id as id0_,
book0_.contentLanguage as contentL2_0_, book0_.description as descript3_0_,
book0_.illustrations as illustra4_0_, book0_.isbn as isbn0_, book0_.nbOfPage as
nbOfPage0_, book0_.price as price0_, book0_.title as title0_ from Book book0_ where
'scifi' in (select )
10:53:14,621 DEBUG SessionFactoryImpl:557 - Checking 0 named SQL queries
10:53:14,621 ERROR SessionFactoryImpl:422 - Error in named query: findAllScifiBooks
org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree [SELECT b FROM
org.beginningee6.tutorial.Book b WHERE 'scifi' member of b.tags]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
at org.hibernate.hql.ast.QueryTranslatorImpl.generate(QueryTranslatorImpl.java:244)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:205)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
at
org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:547)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:411)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842)
at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)
at
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at org.beginningee6.tutorial.BookTest.initEntityManager(BookTest.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:94)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:192)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
{code}
Attached is the entity and the unit test that makes it break. The Maven project uses
GlassFish (EclipseLink) by default, so you can make it run using {{mvn -Pjboss test}}.
Also you need the Derby database running (I'm not using an inmemory DB for this test)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: