List<ActivityDefinition> list = entityManagerTemplate.find(ActivityDefinition.class, "select x from "
+ QueryUtils.getTypeName(ActivityDefinition.class) + " x where x.processDefinition = :definition and x.name = :name", params);
if (!list.isEmpty()) {
return list.get(0);
} else {
ActivityDefinition answer = new ActivityDefinition();
answer.setName(activityName);
answer.setProcessDefinition(ProcessDefinition.getRefreshedProcessDefinition(entityManagerTemplate, definition));
entityManagerTemplate.persist(answer);
return answer;
}
}