UnsupportedOperationException when using addScalar on querys created via NamedSQLQueryDefinition

Description

When creating an Query via NamedSQLQueryDefinition (eg. via @NamedNativeQuery annotation in JavaEE) an java.lang.UnsupportedOperationException will be thrown when invoking addScalar(..)

This could be verified by exact code review:

For me, the fault seems to be at the constructor org.hibernate.intenal.SQLQueryImpl(NamedSQLQueryDefinition queryDef, SessionImplementor session, ParameterMetadata parameterMetadata).
At line 95 the local variable 'queryReturns' is initialized by using Arrays.asList(..). This will create an simplified derivation of AbstractList wich will only provide reading operations but when executing the query after adding an scalar SqlQueryImpl.prepare() will call queryReturns.clear() (see line 233).

The other constructor org.hibernate.internal.SQLQueryImpl(final String sql, final String returnAliases[], final Class returnClasses[], final SessionImplementor session, ParameterMetadata parameterMetadata) is doing this better.
As you can see at line 140 the local variable 'queryReturns' is initalized by using new ArrayList<NativeSQLQueryReturn>() instead of Arrays.asList(..).

In Hibernate 3 the Bug was allready existent, but the exception has been thrown when calling addScalar(), now it just will be thrown when excecute the query.

Environment

JBoss EAP 6.1.1, Oracle10g, Hibernate 4.2.0.SP1

Activity

Show:
Henrik Hoffmann
January 15, 2014, 12:22 PM

"Real" JEE Example for JBoss EAP 6.1.x, showing the mentioned UnsupportedOperationException.
Its based on hibernate4 quickstart project.

Henrik Hoffmann
January 15, 2014, 12:23 PM

oh well, for an "real" JEE application showing this exception watch ExceptionWithNamedQueryAndAddScalar.zip

for an synthetic testcase please have a look on my pull request

thank you!

Brett Meyer
January 16, 2014, 6:26 AM

Thank you for the pull request!

Henrik Hoffmann
January 30, 2014, 11:03 PM

Could you please provide this bugfix for 4.2.9?

Brett Meyer
January 31, 2014, 1:44 PM

Sorry , it was already in the 4.2 branch, but I just didn't set the fix version for some reason. Thanks for pinging me!

Assignee

Brett Meyer

Reporter

Henrik Hoffmann

Fix versions

Labels

backPortable

None

Suitable for new contributors

Yes, likely

Requires Release Note

Affirmative

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure