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

Wrong order parameter binding when filters are used in conjunction with component type parameters and subqueries


    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects versions: 5.1.0, 5.0.9, 5.2.1
    • Fix versions: 5.2.2
    • Components: hibernate-core
    • Labels:
    • Environment:
      Hibernate 5.2.1, SQL
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
    • Sprint:


      Hibernate creates a SQL-statement with position based parameters in the wrong order. That is, the sql statement creation works as expected but the parameters that are placed into the place holders are in the wrong order.
      This only happens if a filter ist used in a query and a subquery with entities that have a composite-id . For some reason hibernate does not set the parameter of the second filter in the subquery but uses the next parameter instead.
      Constructing such a statement is very easy. All you need is a filter, and an entities with a composite-id.
      Make sure the filter is used by the entity. (in the entitie's (*.).hbm.xml or annotation)
      Then create a Createria from the class and add a Restriction for that classes composite id.
      Furthermore create a DetachedCriteria that will be used in a subquery, which consists of a restriction and any Projection. After that, append the DetachedCriteria with a Property to the first Criteria.
      and then call list() on the Criteria.
      The result is a SQL statement with the filter in the main statement and the sub statement, and parameters assigned by position. But in the subquery, the parameters are mixed and therefore appended at the wrong place in the query.
      In the beste case this statement crashes because of parameter type missmatch, but it's also possible that the parameter types fit and an invalid entry will be created silently.
      A complete Test is appended to this ticket.




            • Votes:
              0 Vote for this issue
              4 Start watching this issue


              • Created: