ParameterTranslationsImpl fails to correctly determine parameter type

Description

For the conditions in the form "(aram IS NULL OR alias.someField = aram)", the HQL parses would not correctly determine the type of param, unless the conditions are swapped like "(alias.someField = aram OR aram IS NULL)". The reason is that NamedParamTempHolder classes are created for all parameter entries, in the order they appear in the query. The first occurrence (aram IS NULL) would have its expectedType set to null, and the second occurrence would use the param holder created by the first occurrence, without checking whether it can improve it in any way (which it can - the expectedType for second occurrence is correctly determined to be Long).

Proposed fix would be to check for this particular condition, enhancing paramHolder if possible, with new information:

old code:
if ( paramHolder == null ) {
paramHolder = new NamedParamTempHolder();
paramHolder.name = namedSpec.getName();
paramHolder.type = namedSpec.getExpectedType();
namedParameterMap.put( namedSpec.getName(), paramHolder );
}

new code:
if ( paramHolder == null ) {
paramHolder = new NamedParamTempHolder();
paramHolder.name = namedSpec.getName();
paramHolder.type = namedSpec.getExpectedType();
namedParameterMap.put( namedSpec.getName(), paramHolder );
+ } else if (paramHolder.getExpectedType() == null && namedSpec.getExpectedType() != null) {
+ paramHolder.type = namedSpec.getExpectedType();
}

Environment

None

Activity

Show:
Gail Badner
June 17, 2015, 11:10 PM

Fixed in master, 4.3, and 4.2 branches. Thanks for the test case and fix (and sorry it took so long to be fxied).

Gail Badner
June 17, 2015, 10:10 PM

Thanks, I have it reproduced now.

Andrew Schmidt
June 17, 2015, 9:38 PM

Sql Server 2008.

Dialect:
org.hibernate.dialect.SQLServer2008Dialect

Gail Badner
June 17, 2015, 9:35 PM

Andrew Schmidt, I'm having trouble reproducing this with SQL Server. What version of SQL Server are you using and which dialect are you using?

Andrew Schmidt
January 14, 2015, 3:28 PM

I've been testing it inside Wildfly and SQL Server. The container is not important, but the databas is. You'll need to deploy your example-ds.xml with the appropriate credentials.

When the deployment starts you'll get the error:

when the following query runs:

Fixed

Assignee

Gail Badner

Reporter

Alex Savitsky

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor