NPE (in ReflectHelper.getConstructor) during createQuery without alias with one entity (wich use several tables)

Description

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.

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

Activity

Show:
Brett Meyer
April 7, 2014, 5:48 PM

In an effort to clean up, in bulk, tickets that are most likely out of date, we're transitioning all ORM 3 tickets to an "Awaiting Test Case" state. Please see http://in.relation.to/Bloggers/HibernateORMJIRAPoliciesAndCleanUpTactics for more information.

If this is still a legitimate bug in ORM 4, please provide either a test case that reproduces it or enough detail (entities, mappings, snippets, etc.) to show that it still fails on 4. If nothing is received within 3 months or so, we'll be automatically closing them.

Thank you!

Brett Meyer
July 8, 2014, 3:11 PM

Bulk rejecting stale issues. If this is still a legitimate issue on ORM 4, feel free to comment and attach a test case. I'll address responses case-by-case. Thanks!

Assignee

Unassigned

Reporter

Félix Gerzaguet

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure