How to create native query on process definition?

i used the following code in activiti

NativeProcessDefinitionQuery query = repositoryService.createNativeProcessDefinitionQuery();
	query.sql(" select  rownum||'' as Id_,"
         +"    rev_,                  "
         +"   category_,              "
         +"  name_,                   "
         +"  key_,                    "
         +"  version_,                "
         +"   deployment_id_,         "
         +"   resource_name_,         "
         +"   dgrm_resource_name_,    "
         +"   description_,           "
         +"  has_start_form_key_,     "
         +"   has_graphical_notation_,"
         +"   suspension_state_,      "
         +"   tenant_id_  from (      select distinct 		'' as Id_,    "
			+ " 0  as rev_,                     "
			+ " '' as  category_,               "
			+ " def.name_,                      "
			+ " def.key_,                       "
			
			+ "  0  as version_,                "
			+ " '' as deployment_id_,           "
			+ " '' as resource_name_,           "
			+ " '' as dgrm_resource_name_,      "
			+ " '' as description_,             "
			+ " 0 as  has_start_form_key_,      "
			+ " 0 as   has_graphical_notation_, "
			+ " 0 as  suspension_state_,       "
			+ " '' as   tenant_id_              " + " from "
			+ managementService.getTableName(HistoricProcessInstance.class)
			+ " RES " + "  left outer join ACT_RE_PROCDEF DEF "
			+ "  on RES.PROC_DEF_ID_ = DEF.ID_  "
			+ "  WHERE (exists (select LINK.USER_ID_  "
			+ "                  from ACT_HI_IDENTITYLINK LINK  "
			+ "                where USER_ID_ =#{userId}  "
			+ "                  and LINK.PROC_INST_ID_ = RES.ID_)) ) ");
	query.parameter("userId", SecurityUtility.getAuthenticatedUserId().toString());

but because repositoryService of camunda don’t have createNativeProcessDefinitionQuery method i dont know how do it. please help me.

1 Like

Hi @vahidalz,

I believe this feature does not exist in Camunda as of now. Why do you need to make a custom query, i.e. what do you need that the regular query does not provide?

Cheers,
Thorben

@thorben i want to get distinct list of all process definition that user involved to,each any task of that assigned to user or assigned to user groups .What solution do you suggest?

Hi @vahidalz
Have a look at below link
https://docs.camunda.org/manual/7.6/examples/tutorials/custom-queries/#custom-mybatis-queries