cancel
Showing results for 
Search instead for 
Did you mean: 

how to delete the HistoricActivityInstance by the id of its?

xiangyuely
Champ in-the-making
Champ in-the-making
Because of some specific business,I want to delete a record of HistoricActivityInstance by id, but I found that there is not the delete sql to delete the HistoricActivityInstance  by id in HistoricActivityInstance.xml,what should I do to solve this problem?I need some help,thanks!
3 REPLIES 3

jorge_villalobo
Champ in-the-making
Champ in-the-making
Hi,

Within the class "org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceManager.java" the method "deleteHistoricActivityInstance (String historicActivityInstanceId)" is available but can not run because the judgment finds no declared in xml configuration files for mapping database.

I solved the problem as follows:

Was included in the file "src/main/resources/org/activiti/db/mapping/entity/HistoricActivityInstance.xml" the following lines to achieve the desired performance.

     <Delete id="deleteHistoricActivityInstance">
         delete from ACT_HI_ACTINST where ID_ = # {id}
    </ delete>

xiangyuely
Champ in-the-making
Champ in-the-making
As you write,I add in the HistoricActivityInstance.xml as follows: 
  <delete id="deleteHistoricActivityInstance">
      delete from ACT_HI_ACTINST where ID_ = #{id}
  </delete>
but it causes the following error:

org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for deleteHistoricActivityInstance
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for deleteHistoricActivityInstance
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:124)
at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:135)
at org.activiti.engine.impl.db.DbSqlSession$DeleteById.execute(DbSqlSession.java:146)
at org.activiti.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.java:461)
at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:349)
at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:149)
at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:105)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)
at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
at cn.sec.ac.impl.CustomServiceImpl.completeTaskRollBack(CustomServiceImpl.java:25)
at cn.sec.ac.ProcessEngineAskForLeave.main(ProcessEngineAskForLeave.java:53)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for deleteHistoricActivityInstance
at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:595)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:437)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:430)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:121)

So,I don't understand,I have the delete sql in the HistoricActivityInstance.xml, why it can't be put in Mapped Statements when the process engine is initialized?

jorge_villalobo
Champ in-the-making
Champ in-the-making
I'm working with version 5.9 of the code of Activiti, the error showed when I tried to delete a historical record by ID.
fix it by adding the lines
<delete id="deleteHistoricActivityInstance">
    delete from ACT_HI_ACTINST where ID_ = #{id}
</delete>

after

<delete id="deleteHistoricActivityInstancesByProcessInstanceId">
    delete from ACT_HI_ACTINST where PROC_INST_ID_ = #{processInstanceId}
</delete>

like I said.

After modifying the file HistoricActivityInstance.xml, I generate the distribution again, start the environment and it works.

But, if you´re modifying the  activiti-engine.jar, I recommended turning off the environment, modify the jar and start the environment

Hope this help