DbSessionImpl.deleteProcessDefinitionHistory(String processDefinitionId) needs to remove HistoryActivityInstanceImpl when deleting HistoryProcessInstanceImpl since there is a foreign key constrain FK_HACTI_HPROCI in the hibernate mapping, the following implementation should do the trick:
public void deleteProcessDefinitionHistory(String processDefinitionId) {
List<HistoryProcessInstanceImpl> historyProcessInstances = session
.createCriteria(HistoryProcessInstanceImpl.class)
.add(Restrictions.eq("processDefinitionId", processDefinitionId))
.list();
for (HistoryProcessInstanceImpl hpi : historyProcessInstances) {
List<HistoryActivityInstanceImpl> historyActivityInstances = session
.createCriteria(HistoryActivityInstanceImpl.class)
.add(Restrictions.eq("historyProcessInstance", hpi))
.list();
for (HistoryActivityInstanceImpl hai : historyActivityInstances)
session.delete(hpi);
}
}