Uploaded image for project: 'camunda BPM'
  1. camunda BPM
  2. CAM-12703

OR Query is translated to AND for HistoricTaskInstanceQuery

XMLWordPrintable

    • Icon: Bug Report Bug Report
    • Resolution: Fixed
    • Icon: L3 - Default L3 - Default
    • 7.15.0-alpha3, 7.15.0
    • 7.14.0
    • None

      Given a query like this:

      List<HistoricTaskInstance> tasks = execution
      				.getProcessEngineServices()
      				.getHistoryService()
      				.createHistoricTaskInstanceQuery()
      				.tenantIdIn("Test_Tenant")
      				.or()
      				.taskHadCandidateGroup("GROUP_TEST")
      				.taskHadCandidateUser("USER_TEST")
      				.endOr()
      				.orderByHistoricTaskInstanceEndTime()
      				.desc()
      				.list();
      

      the resulting SQL is

      SELECT DISTINCT RES.* 
      FROM   act_hi_taskinst RES 
      WHERE  ( 1 = 1 
               AND RES.tenant_id_ IN ( ? ) ) 
             AND ( 1 = 1 
                   AND RES.id_ IN (SELECT task_id_ 
                                   FROM   act_hi_identitylink HIL 
                                   WHERE  HIL.type_ = 'candidate' 
                                          AND HIL.user_id_ = ? 
                                          AND HIL.type_ = 'candidate' 
                                          AND HIL.group_id_ = ?) ) 
             AND ( RES.tenant_id_ IS NULL ) 
      ORDER  BY RES.end_time_ DESC 
      LIMIT  ? offset ? 
      

      Note that the query criteria inside the or query are concatenated with AND instead of OR.

      Root Cause:
      The AND is hardcoded into the SQL statement: https://github.com/camunda/camunda-bpm-platform/blob/master/engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/HistoricTaskInstance.xml#L321-L330

      It should use the dynamic queryType like here: https://github.com/camunda/camunda-bpm-platform/blob/master/engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/Task.xml#L351

      This is confirmed with 7.14.0 but should also affect older versions since the relevant code was introduced with CAM-4911 (7.5) and probably missed when introducing the or query support with CAM-9676 (7.12).

        This is the controller panel for Smart Panels app

              miklas.boskamp Miklas Boskamp
              miklas.boskamp Miklas Boskamp
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: