|
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.
|