<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
  version="2.0">

  <!-- process instance queries -->
  <named-query name="getProcessInstances">

    <query>
      select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        ProcessInstanceLog log
      ORDER BY
        log.processId, log.start
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getProcessInstancesByStatus">
    <query>
      select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance)

      from
        ProcessInstanceLog log
      where
        log.status in (:states)
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getProcessInstancesByStatusAndInitiator">
    <query>
      select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
        )
      from
        ProcessInstanceLog log
      where
        log.status in (:states) and log.identity = :initiator
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getProcessInstancesByDeploymentId">
    <query>
      select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
        )
      from
        ProcessInstanceLog log
      where
        log.externalId=:externalId
        and log.status in (:states)
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getProcessInstancesByProcessDefinition">
    <query>
     select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
        )
      from
        ProcessInstanceLog log
      where
        log.processId =:processDefId
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getProcessInstanceById">
    <query>
     select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
        )
      from
        ProcessInstanceLog log
      where
        log.processInstanceId =:processId
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  <named-query name="getProcessInstanceByCorrelationKey">
    <query>
     select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
        )
      from
        ProcessInstanceLog log
      where
        log.correlationKey =:correlationKey
        and log.status = 1
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  <named-query name="getProcessInstancesByCorrelationKey">
    <query>
     select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
        )
      from
        ProcessInstanceLog log
      where
        log.correlationKey like :correlationKey
        order by log.id
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  <named-query name="getProcessInstancesByCorrelationKeyAndStatus">
    <query>
     select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
        )
      from
        ProcessInstanceLog log
      where
        log.correlationKey like :correlationKey and log.status in (:states)
        order by log.id
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>


  <named-query name="getProcessInstancesByProcessIdAndStatus">
    <query>
     select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        ProcessInstanceLog log
      where
        log.status in (:states) and log.processId like :processId
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getProcessInstancesByProcessIdAndStatusAndInitiator">
    <query>
     select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        ProcessInstanceLog log
      where
        log.status in (:states) and log.processId like :processId and log.identity = :initiator
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getProcessInstancesByProcessNameAndStatus">
    <query>
     select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        ProcessInstanceLog log
      where
        log.status in (:states) and log.processName like :processName
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getProcessInstancesByProcessNameAndStatusAndInitiator">
    <query>
     select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        ProcessInstanceLog log
      where
        log.status in (:states) and log.processName like :processName and log.identity = :initiator
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  <named-query name="getProcessInstancesByVariableName">

    <query>
      select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        ProcessInstanceLog log
      where log.status in (:states) and log.processInstanceId in (select vlog.processInstanceId from
        VariableInstanceLog vlog where vlog.variableId like :variable)
      ORDER BY
        log.processId, log.start
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  <named-query name="getProcessInstancesByVariableNameAndValue">

    <query>
      select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        ProcessInstanceLog log
      where log.status in (:states) and log.processInstanceId in 
      (select vlog.processInstanceId from VariableInstanceLog vlog where vlog.variableId=:variable and vlog.value like :variableValue
      and vlog.id in (select max(vlog2.id) from VariableInstanceLog vlog2 where vlog2.variableId = vlog.variableId group by vlog2.processInstanceId))
      ORDER BY
        log.processId, log.start
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query> 
  
  <named-query name="getProcessInstancesByParent">
    <query>
      select
      new org.jbpm.kie.services.impl.model.ProcessInstanceDesc(
      log.processInstanceId,
      log.processId,
      log.processName,
      log.processVersion,
      log.status,
      log.externalId,
      log.start,
      log.identity,
      log.processInstanceDescription,
      log.correlationKey,
      log.parentProcessInstanceId,
      log.slaDueDate,
      log.slaCompliance)

      from
        ProcessInstanceLog log
      where
        log.status in (:states)
        and log.parentProcessInstanceId = :parentId
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>   
  
  <!-- node instance queries -->

  <named-query name="getProcessInstanceFullHistory">
    <query>
      select
      new org.jbpm.kie.services.impl.model.NodeInstanceDesc(
      log.nodeInstanceId,
      log.nodeId,
      log.nodeName,
      log.nodeType,
      log.externalId,
      log.processInstanceId,
      log.date,
      log.connection,
      log.type,
      log.workItemId,
      log.referenceId,
      log.nodeContainerId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        NodeInstanceLog log
      where
        log.processInstanceId=:processId
      ORDER BY 
        log.date DESC, log.id DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  <named-query name="getProcessInstanceFullHistoryByType">
    <query>
      select
      new org.jbpm.kie.services.impl.model.NodeInstanceDesc(
      log.nodeInstanceId,
      log.nodeId,
      log.nodeName,
      log.nodeType,
      log.externalId,
      log.processInstanceId,
      log.date,
      log.connection,
      log.type,
      log.workItemId,
      log.referenceId,
      log.nodeContainerId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        NodeInstanceLog log
      where
        log.processInstanceId=:processId 
        AND log.type=:type
      ORDER BY 
        log.date DESC, log.id DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>


  <named-query name="getProcessInstanceActiveNodes">
    <query>
      select
      new org.jbpm.kie.services.impl.model.NodeInstanceDesc(
      log.nodeInstanceId,
      log.nodeId,
      log.nodeName,
      log.nodeType,
      log.externalId,
      log.processInstanceId,
      log.date,
      log.connection,
      log.type,
      log.workItemId,
      log.referenceId,
      log.nodeContainerId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        NodeInstanceLog log
      where
        log.nodeInstanceId in ( select nil.nodeInstanceId from NodeInstanceLog nil where nil.processInstanceId=:processId  
                    GROUP BY nil.nodeInstanceId
                    HAVING sum(nil.type) = 0)
        and log.type = 0  
        and log.processInstanceId=:processId          
      order by
        log.id ASC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getProcessInstanceCompletedNodes">
    <query>
      select
      new org.jbpm.kie.services.impl.model.NodeInstanceDesc(
      log.nodeInstanceId,
      log.nodeId,
      log.nodeName,
      log.nodeType,
      log.externalId,
      log.processInstanceId,
      log.date,
      log.connection,
      log.type,
      log.workItemId,
      log.referenceId,
      log.nodeContainerId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        NodeInstanceLog log
      where
        log.type = 1
        and log.processInstanceId=:processId
      ORDER BY 
        log.id ASC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  <named-query name="getNodeInstanceForWorkItem">
    <query>
      select
      new org.jbpm.kie.services.impl.model.NodeInstanceDesc(
      log.nodeInstanceId,
      log.nodeId,
      log.nodeName,
      log.nodeType,
      log.externalId,
      log.processInstanceId,
      log.date,
      log.connection,
      log.type,
      log.workItemId,
      log.referenceId,
      log.nodeContainerId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        NodeInstanceLog log
      where
        log.workItemId=:workItemId
       	and log.type = 0   
      ORDER BY 
        log.nodeInstanceId, log.id ASC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getNodeInstancesByNodeType">
    <query>
      select
      new org.jbpm.kie.services.impl.model.NodeInstanceDesc(
      log.nodeInstanceId,
      log.nodeId,
      log.nodeName,
      log.nodeType,
      log.externalId,
      log.processInstanceId,
      log.date,
      log.connection,
      log.type,
      log.workItemId,
      log.referenceId,
      log.nodeContainerId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        NodeInstanceLog log
      where
        log.processInstanceId=:processInstanceId
        and log.nodeType in (:nodeTypes)
      ORDER BY 
        log.nodeInstanceId
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  <named-query name="getNodeInstancesByCorrelationKeyAndNodeType">
    <query>
      select
      new org.jbpm.kie.services.impl.model.NodeInstanceDesc(
      log.nodeInstanceId,
      log.nodeId,
      log.nodeName,
      log.nodeType,
      log.externalId,
      log.processInstanceId,
      log.date,
      log.connection,
      log.type,
      log.workItemId,
      log.referenceId,
      log.nodeContainerId,
      log.slaDueDate,
      log.slaCompliance
      )
      from
        ProcessInstanceLog plog,
        NodeInstanceLog log
      where
        plog.correlationKey like :correlationKey
        and plog.status in (:states) 
        and plog.processInstanceId=log.processInstanceId
        and log.nodeType in (:nodeTypes)
      ORDER BY 
        log.nodeInstanceId
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>  

  <!-- variable instance queries -->
  <named-query name="getVariablesCurrentState">
    <query>
      select
      new org.jbpm.kie.services.impl.model.VariableStateDesc(
      log.variableId,
      log.variableInstanceId,
      log.oldValue,
      log.value,
      log.externalId,
      log.processInstanceId,
      log.date
      )
      from
        VariableInstanceLog log
      where
        log.processInstanceId =:processInstanceId AND log.id in 
        (select max(vss.id) FROM VariableInstanceLog vss WHERE vss.processInstanceId =:processInstanceId group by vss.variableId ) 
        order by log.id
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getVariableHistory">
    <query>
     select
      new org.jbpm.kie.services.impl.model.VariableStateDesc(
      log.variableId,
      log.variableInstanceId,
      log.oldValue,
      log.value,
      log.externalId,
      log.processInstanceId,
      log.date
      )
      from
        VariableInstanceLog log
      where
        log.processInstanceId =:processInstanceId AND log.variableId =:variableId 
      order by 
        log.id DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  <named-query name="getTaskInstanceById">
    <query>
        select 
	      new org.jbpm.kie.services.impl.model.UserTaskInstanceDesc(
	      a.taskId,
	      a.status,
	      a.activationTime,
	      a.name,
	      a.description,
	      a.priority,
	      a.actualOwner,
	      a.createdBy,
	      a.deploymentId,
	      a.processId,
	      a.processInstanceId,
	      a.createdOn,
	      a.dueDate
	      )
        from 
        	AuditTaskImpl a 
        where 
        	a.taskId = :taskId 
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  <named-query name="getTaskInstanceByWorkItemId">
    <query>
        select 
	      new org.jbpm.kie.services.impl.model.UserTaskInstanceDesc(
	      a.taskId,
	      a.status,
	      a.activationTime,
	      a.name,
	      a.description,
	      a.priority,
	      a.actualOwner,
	      a.createdBy,
	      a.deploymentId,
	      a.processId,
	      a.processInstanceId,
	      a.createdOn,
	      a.dueDate
	      )
        from 
        	AuditTaskImpl a
        where 
        	a.workItemId = :workItemId 
        	
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
    <named-query name="getTaskInstancesByProcessInstanceId">
    <query>
        select 
        new org.jbpm.kie.services.impl.model.UserTaskInstanceDesc(
        a.taskId,
        a.status,
        a.activationTime,
        a.name,
        a.description,
        a.priority,
        a.actualOwner,
        a.createdBy,
        a.deploymentId,
        a.processId,
        a.processInstanceId,
        a.createdOn,
        a.dueDate
        )
        from 
          AuditTaskImpl a 
        where 
          a.processInstanceId = :processInstanceId
          and a.status in ( :statuses) 
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <!-- deployment store named queries -->
  <named-query name="getDeploymentUnit">

    <query>
      select d from DeploymentStoreEntry d where d.deploymentId=:deploymentId
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  <named-query name="getDeploymentUnitsByDate">

    <query>
      select d from DeploymentStoreEntry d where d.updateDate >= :ludate
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  
  <named-query name="getDeploymentUnitsByState">

    <query>
      select d from DeploymentStoreEntry d where d.state in (:state)
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  
  <!-- query definitions storage named queries -->
  <named-query name="getQueryDefinitionByName">

    <query>
      select qd from QueryDefinitionEntity qd where name = :name
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  <named-query name="getQueryDefinitions">

    <query>
      select qd from QueryDefinitionEntity qd
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  
  
  <!-- admin error handling queries -->
  
  <named-query name="getErrorByIdSkipAckCheck">
    <query>
     select
      new org.kie.internal.runtime.error.ExecutionError(
      error.errorId,
      error.type,
      error.deploymentId,
      error.processInstanceId,
      error.processId,
      error.activityId,
      error.activityName,
      error.jobId,
      error.errorMessage,
      error.error,
      error.acknowledged,
      error.acknowledgedBy,
      error.acknowledgedAt,
      error.errorDate
      )
      from
        ExecutionErrorInfo error
      where
        error.errorId =:errorId  
      order by 
        error.errorDate DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query> 
  
  <named-query name="getErrorById">
    <query>
     select
      new org.kie.internal.runtime.error.ExecutionError(
      error.errorId,
      error.type,
      error.deploymentId,
      error.processInstanceId,
      error.processId,
      error.activityId,
      error.activityName,
      error.jobId,
      error.errorMessage,
      error.error,
      error.acknowledged,
      error.acknowledgedBy,
      error.acknowledgedAt,
      error.errorDate
      )
      from
        ExecutionErrorInfo error
      where
        error.errorId =:errorId  and
        error.acknowledged in (:ack) 
      order by 
        error.errorDate DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>  
  
  <named-query name="getErrorsByTaskId">
    <query>
     select
      new org.kie.internal.runtime.error.ExecutionError(
      error.errorId,
      error.type,
      error.deploymentId,
      error.processInstanceId,
      error.processId,
      error.activityId,
      error.activityName,
      error.jobId,
      error.errorMessage,
      error.acknowledged,
      error.acknowledgedBy,
      error.acknowledgedAt,
      error.errorDate
      )
      from
        ExecutionErrorInfo error
      where
        error.type= 'Task' and
        error.activityId =:taskId and
        error.acknowledged in (:ack) 
      order by 
        error.errorDate DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>  
  
  <named-query name="getErrorsByTaskName">
    <query>
     select
      new org.kie.internal.runtime.error.ExecutionError(
      error.errorId,
      error.type,
      error.deploymentId,
      error.processInstanceId,
      error.processId,
      error.activityId,
      error.activityName,
      error.jobId,
      error.errorMessage,
      error.acknowledged,
      error.acknowledgedBy,
      error.acknowledgedAt,
      error.errorDate
      )
      from
        ExecutionErrorInfo error 
      where
        error.type= 'Task' and
        error.activityName =:taskName and
        error.acknowledged in (:ack) 
      order by 
        error.errorDate DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>  
  
  <named-query name="getErrorsByTaskNameProcessId">
    <query>
     select
      new org.kie.internal.runtime.error.ExecutionError(
      error.errorId,
      error.type,
      error.deploymentId,
      error.processInstanceId,
      error.processId,
      error.activityId,
      error.activityName,
      error.jobId,
      error.errorMessage,
      error.acknowledged,
      error.acknowledgedBy,
      error.acknowledgedAt,
      error.errorDate
      )
      from
        ExecutionErrorInfo error
      where
        error.type= 'Task' and
        error.processId =:processId  and
        error.activityName =:taskName and
        error.acknowledged in (:ack) 
      order by 
        error.errorDate DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>  
  
  <named-query name="getErrorsByTaskNameProcessIdDeploymentId">
    <query>
     select
      new org.kie.internal.runtime.error.ExecutionError(
      error.errorId,
      error.type,
      error.deploymentId,
      error.processInstanceId,
      error.processId,
      error.activityId,
      error.activityName,
      error.jobId,
      error.errorMessage,
      error.acknowledged,
      error.acknowledgedBy,
      error.acknowledgedAt,
      error.errorDate
      )
      from
        ExecutionErrorInfo error
      where
        error.type= 'Task' and
        error.deploymentId =:deploymentId and
        error.processId =:processId  and
        error.activityName =:taskName and
        error.acknowledged in (:ack) 
      order by 
        error.errorDate DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query> 
  
  <named-query name="getErrorsByProcessId">
    <query>
     select
      new org.kie.internal.runtime.error.ExecutionError(
      error.errorId,
      error.type,
      error.deploymentId,
      error.processInstanceId,
      error.processId,
      error.activityId,
      error.activityName,
      error.jobId,
      error.errorMessage,
      error.acknowledged,
      error.acknowledgedBy,
      error.acknowledgedAt,
      error.errorDate
      )
      from
        ExecutionErrorInfo error 
      where
        error.deploymentId =:deploymentId and
        error.processId =:processId and
        error.acknowledged in (:ack) 
      order by 
        error.errorDate DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>  
  
  <named-query name="getErrorsByProcessInstanceId">
    <query>
     select
      new org.kie.internal.runtime.error.ExecutionError(
      error.errorId,
      error.type,
      error.deploymentId,
      error.processInstanceId,
      error.processId,
      error.activityId,
      error.activityName,
      error.jobId,
      error.errorMessage,
      error.acknowledged,
      error.acknowledgedBy,
      error.acknowledgedAt,
      error.errorDate
      )
      from
        ExecutionErrorInfo error
      where
        error.processInstanceId =:processInstanceId  and
        error.acknowledged in (:ack) 
      order by 
        error.errorDate DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>  
  
  <named-query name="getErrorsByProcessInstanceIdNodeName">
    <query>
     select
      new org.kie.internal.runtime.error.ExecutionError(
      error.errorId,
      error.type,
      error.deploymentId,
      error.processInstanceId,
      error.processId,
      error.activityId,
      error.activityName,
      error.jobId,
      error.errorMessage,
      error.acknowledged,
      error.acknowledgedBy,
      error.acknowledgedAt,
      error.errorDate
      )
      from
        ExecutionErrorInfo error
      where
        error.processInstanceId =:processInstanceId  and
        error.activityName =:nodeName and
        error.acknowledged in (:ack) 
      order by 
        error.errorDate DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>  
  
  <named-query name="getErrors">
    <query>
     select
      new org.kie.internal.runtime.error.ExecutionError(
      error.errorId,
      error.type,
      error.deploymentId,
      error.processInstanceId,
      error.processId,
      error.activityId,
      error.activityName,
      error.jobId,
      error.errorMessage,
      error.acknowledged,
      error.acknowledgedBy,
      error.acknowledgedAt,
      error.errorDate
      )
      from
        ExecutionErrorInfo error
      where
        error.acknowledged in (:ack) 
      order by 
        error.errorDate DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query> 

  <named-query name="getErrorsByDeploymentId">
    <query>
     select
      new org.kie.internal.runtime.error.ExecutionError(
      error.errorId,
      error.type,
      error.deploymentId,
      error.processInstanceId,
      error.processId,
      error.activityId,
      error.activityName,
      error.jobId,
      error.errorMessage,
      error.acknowledged,
      error.acknowledgedBy,
      error.acknowledgedAt,
      error.errorDate
      )
      from
        ExecutionErrorInfo error
      where
        error.acknowledged in (:ack) and
        error.deploymentId = :deploymentId
      order by 
        error.errorDate DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query> 
  
  <named-query name="getTaskErrors">
    <query>
     select
      new org.kie.internal.runtime.error.ExecutionError(
      error.errorId,
      error.type,
      error.deploymentId,
      error.processInstanceId,
      error.processId,
      error.activityId,
      error.activityName,
      error.jobId,
      error.errorMessage,
      error.acknowledged,
      error.acknowledgedBy,
      error.acknowledgedAt,
      error.errorDate
      )
      from
        ExecutionErrorInfo error
      where
        error.type= 'Task' and
        error.acknowledged in (:ack) 
      order by 
        error.errorDate DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>   
        
</entity-mappings>