]
Gail Badner commented on HHH-1306:
----------------------------------
Paul, please open a new Jira issue with a runnable test case (Java + mapping) that
reproduces the issue.
HQL parsing problem with join fetching of arrays/collections of
values
----------------------------------------------------------------------
Key: HHH-1306
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1306
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.1
Environment: SQL Server
Reporter: Peter Fassev
Assignee: Steve Ebersole
Priority: Minor
Fix For: 3.1.2
Attachments: testcase.zip
There is a parsing exception, which is thrown, when executing the following HQL query
(note that I only want to fetch an association):
select o from A as o inner join fetch o.b as e
The A class looks like:
public class A {
private int id;
private String[] b;
}
And the mapping is:
<class name="A" table="A">
<cache usage="read-write"/>
<id type="int" name="id" unsaved-value="0">
<generator class="native"/>
</id>
<array name="b" table="AB" cascade="all">
<cache usage="read-write"/>
<key column="aId"/>
<index column="index_"/>
<element column="b" type="java.lang.String"
length="1024" not-null="true"/>
</array>
</class>
Than following happens:
java.lang.NullPointerException
at
org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:175)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:637)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:466)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:643)
at
org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:279)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:227)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:105)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:74)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:53)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at
org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:108)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:88)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1540)
at A.main(A.java:76)
Exception in thread "main"
IMPORTANT: Please note, that the previous exception is a secondary exception, which is
due to a small bug in the throw clause. The actual (unthrown) exception (taken from the
source of SelectClause class) should be read as:
...
throw new QueryException(
"query specified join fetching, but the owner " +
"of the fetched association was not present in the select list " +
"(" + fromElement.getClassName() + " -> " +
fromElement.getRealOrigin().getClassName() + ")"
....
But it can not be throwed, because the fromElement is actually NULL, thus the
NullPointerException.
There a simple workaround for this. When the "select" clause (which is actually
not needed) is removed from the query, there is no such exception: "from A as o inner
join fetch o.b as e" - this query does not produce an exception.
But as far as I can see from the documentation, the select clause is perfectly legal, so
I suppose the problem lies somewhere in the HQL Parser. Also, I am having the same
problem with list or sets of components, instead of arrays.
The problem is not present in Hibernate 3.0.
Please see the attached Test case.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: