# ClassCastException FlowableEventListener when executing V5 process definition

**URL:** <https://forum.flowable.org/t/classcastexception-flowableeventlistener-when-executing-v5-process-definition/2902>\
**Category:** Flowable Engine\
**Created:** [November 14, 2018, 12:47pm UTC](https://forum.flowable.org/t/classcastexception-flowableeventlistener-when-executing-v5-process-definition/2902 "2018-11-14T12:47:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnandMahadik](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@AnandMahadik](https://forum.flowable.org/u/AnandMahadik)\
**Post date:** [November 14, 2018, 12:47pm UTC](https://forum.flowable.org/t/classcastexception-flowableeventlistener-when-executing-v5-process-definition/2902/1 "2018-11-14T12:47:18Z")

</div>

Hi,

I have migrated from Activiti 5.21 to Flowable 6.3. After migrating, the new definitions and their instances work fine but for the old definitions when I launch the process instance I get the following error in the event listener.

e.common.impl.event.FlowableEventSupport - Exception while executing event-listener, which was ignored  
java.lang.ClassCastException: org.activiti.engine.impl.persistence.entity.TaskEntity cannot be cast to org.flowable.task.service.impl.persistence.entity.TaskEntity

**My code is as follows in listner -**

import org.flowable.task.service.impl.persistence.entity.TaskEntity;  
…  
…  
…  
case TASK\_CREATED:  
FlowableEntityEvent taskEvent = (FlowableEntityEvent) e;  
**TaskEntity entity = (TaskEntity) taskEvent.getEntity();**  
processDefinitionKey = entity.getTaskDefinitionKey(); …

**If I change the code to following it works**

case TASK\_CREATED:  
if (taskEvent.getEntity() instanceof TaskEntity) {  
TaskEntity entity = (TaskEntity) taskEvent.getEntity();  
processDefinitionKey = entity.getTaskDefinitionKey();  
}else{  
processDefinitionKey = ((org.activiti.engine.impl.persistence.entity.TaskEntity)  
taskEvent.getEntity()).getTaskDefinitionKey()  
}

Is this the correct way of handling the event ? Do We have to handle the backward compatibility in our code like above ?

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [November 26, 2018, 9:24am UTC](https://forum.flowable.org/t/classcastexception-flowableeventlistener-when-executing-v5-process-definition/2902/2 "2018-11-26T09:24:26Z")

</div>

Yes your way of handling the event is correct. You would need to have a way of handling both v5 and v6 entities.

This might be a bit inconvenient, but the idea is that the V5 instances would finish eventually and you would be able to remove the code

Cheers,  
Filip
