IBM BPM, V8.0.1, All platforms > Programming IBM BPM > Developing client applications for BPEL processes and tasks > Developing EJB client applications > Developing applications for BPEL processes > Manage the lifecycle of a BPEL process
Delete process instances
Completed process instances are automatically deleted from the Business Process Choreographer database if the corresponding property is set for the process template in the process model. You might want to keep process instances in your database, for example, to query data from process instances that are not written to the audit log. However, stored process instance data does not only impact disk space and performance but also prevents process instances that use the same correlation set values from being created. Therefore, you should regularly delete process instance data from the database.
To delete a process instance, you need process administrator rights and the process instance must be a top-level process instance.
The following example shows how to delete all of the finished process instances.
Procedure
- List the process instances that are finished.
FilterOptions fo = new FilterOptions(); fo.setSelectedAttributes("PIID"); fo.setQueryCondition("STATE=STATE_FINISHED"); EntityResultSet result = process.queryEntities("PROCESS_INSTANCE", fo, null, null);This action returns a query result set that lists process instances that are finished.
- Delete the process instances that are finished.
for (int i = 0; i < result.getEntities().size(); i++) { PIID piid = (PIID) result.getEntities().get(i); process.delete(piid);}This action deletes the selected process instance and its inline tasks from the database.