NPE (in ReflectHelper.getConstructor) during createQuery without alias with one entity
(wich use several tables)
----------------------------------------------------------------------------------------------------------------
Key: HHH-5621
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5621
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.0.CR2
Environment: Gentoo Linux
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Hibernate 3.6.0.CR2
tested DB: PostgreSQL 8.4, HSQLDB 1.8.0.10
Reporter: Félix Gerzaguet
Priority: Minor
Attachments: TestCaseCreateQueryWithoutAliasNPE.jar
During a session.createQuery like:
Query query6 = session.createQuery("select new Something(id, event, dummyField)
" +
"from Something" );
A NPE is thrown:
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.util.ReflectHelper.getConstructor(ReflectHelper.java:343)
at
org.hibernate.hql.ast.tree.ConstructorNode.resolveConstructor(ConstructorNode.java:176)
at org.hibernate.hql.ast.tree.ConstructorNode.prepare(ConstructorNode.java:150)
at org.hibernate.hql.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:996)
I join an test case.
All versions of hibernate seems affected (from 3.2.6.ga to 3.6.0.RC2).
This is a minor issue since an easy workaround is available: you just have to use an alias
to qualifie the properties
For the preceding example, we will have:
Query query3 = session.createQuery("select new Something(sthg.id, sthg.event,
sthg.dummyField) " +
"from Something sthg" );
Possible fix:
As described in the testCase, I fix this by a one character fix:
In org.hibernate.hql.ast.HqlSqlWalker in method isNonQualifiedPropertyRef,
change from
if ( fromElements.size() == 1 ) {
to
if ( fromElements.size() >= 1 ) {
This could means that when a property is not qualified, we leave a chance for this
property to be found on the first explicit element of the from clause.
I test this fix on the 3.5.5-Final code and I was able to run the test suite without
failures.
I can't think of a test case in which this fix could lead to a regression but I'm
not an Hibernate Guru so comments are welcome.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira