Uploaded image for project: 'Hibernate ORM'
  1. HHH-2851

ParameterTranslationsImpl fails to correctly determine parameter type

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.2.5, 4.3.8
    • Fix Version/s: 4.2.20, 5.0.0.CR2, 4.3.11
    • Component/s: query-hql
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      For the conditions in the form "(:param IS NULL OR alias.someField = :param)", the HQL parses would not correctly determine the type of param, unless the conditions are swapped like "(alias.someField = :param OR :param 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 (:param 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(); }

        Attachments

        1. HibernateTestCase.zip
          6.46 MB
        2. patch.txt
          0.8 kB
        3. test-hibernate.zip
          5 kB

          Issue links

            Activity

              People

              • Votes:
                27 Vote for this issue
                Watchers:
                14 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: