# Error when trying to access a task within the code: java.lang.ClassCastException: org.flowable.task.service.impl.persistence.entity.TaskEntityImpl cannot be cast to org.flowable.task.service.impl.persistence.entity.TaskEntity

**URL:** <https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430>\
**Category:** Flowable Engine\
**Created:** [August 28, 2019, 10:36pm UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430 "2019-08-28T22:36:27Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sruni5](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Sruni5](https://forum.flowable.org/u/Sruni5)\
**Post date:** [August 28, 2019, 10:36pm UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/1 "2019-08-28T22:36:27Z")

</div>

I am using flowable-engine-6.5.0-SNAPSHOT and receive the following error when a task tries to access the processInstanceId. The following is the stack trace:

java.lang.ClassCastException: org.flowable.task.service.impl.persistence.entity.TaskEntityImpl cannot be cast to org.flowable.task.service.impl.persistence.entity.TaskEntity  
at org.flowable.task.service.impl.TaskServiceImpl.getTask(TaskServiceImpl.java:38) ~[classes/:?]  
at org.flowable.engine.impl.cmd.NeedsActiveTaskCmd.execute(NeedsActiveTaskCmd.java:48) ~[flowable-engine-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.flowable.engine.impl.interceptor.CommandInvoker$1.run(CommandInvoker.java:51) ~[flowable-engine-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperation(CommandInvoker.java:93) ~[flowable-engine-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperations(CommandInvoker.java:72) ~[flowable-engine-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.flowable.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:56) ~[flowable-engine-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.flowable.engine.impl.interceptor.BpmnOverrideContextInterceptor.execute(BpmnOverrideContextInterceptor.java:25) ~[flowable-engine-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.flowable.common.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:53) ~[flowable-engine-common-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:72) ~[flowable-engine-common-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.flowable.common.spring.SpringTransactionInterceptor.lambda$execute$0(SpringTransactionInterceptor.java:56) ~[flowable-spring-common-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:56) ~[flowable-spring-common-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:35) ~[flowable-engine-common-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56) ~[flowable-engine-common-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51) ~[flowable-engine-common-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at org.flowable.engine.impl.TaskServiceImpl.claim(TaskServiceImpl.java:198) ~[flowable-engine-6.5.0-SNAPSHOT.jar:6.5.0-SNAPSHOT]  
at com.quantiply.qiera.flowable.service.FlowableService.getFormDataForCurrentProcessTask(FlowableService.java:290) ~[classes/:?]  
at com.quantiply.qiera.flowable.service.FlowableService$$FastClassBySpringCGLIB$$1246d9a4.invoke() ~[classes/:?]  
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at com.quantiply.qiera.flowable.service.FlowableService$$EnhancerBySpringCGLIB$$766e00f0.getFormDataForCurrentProcessTask() ~[classes/:?]  
at com.quantiply.qiera.service.CaseService.getFormDataForUserTask(CaseService.java:176) ~[classes/:?]  
at com.quantiply.qiera.controller.CasesApiController.getById(CasesApiController.java:179) ~[classes/:?]  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0\_211]  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0\_211]  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0\_211]  
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0\_211]  
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.springframework.web.filter.AbstractRequestLoggingFilter.doFilterInternal(AbstractRequestLoggingFilter.java:246) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:158) ~[spring-boot-actuator-2.0.3.RELEASE.jar:2.0.3.RELEASE]  
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:126) ~[spring-boot-actuator-2.0.3.RELEASE.jar:2.0.3.RELEASE]  
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:111) ~[spring-boot-actuator-2.0.3.RELEASE.jar:2.0.3.RELEASE]  
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90) ~[spring-boot-actuator-2.0.3.RELEASE.jar:2.0.3.RELEASE]  
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]  
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0\_211]  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0\_211]  
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.31.jar:8.5.31]  
at java.lang.Thread.run(Thread.java:748) [?:1.8.0\_211]

---

<div class="post-metadata">

**Author:** ![tijs](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tijs](https://forum.flowable.org/u/tijs)\
**Post date:** [August 29, 2019, 7:17am UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/2 "2019-08-29T07:17:48Z")

</div>

Hi,

That’s a strange exception because TaskEntityImpl implements TaskEntity. Can you share the code that you are using when getting this exception? How are you running Flowable exactly?

Best regards,

Tijs

---

<div class="post-metadata">

**Author:** ![Sruni5](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Sruni5](https://forum.flowable.org/u/Sruni5)\
**Post date:** [August 29, 2019, 7:57am UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/3 "2019-08-29T07:57:55Z")

</div>

Hello Tijs,  
Thank you for your quick response.  
We have embedded the process engine within our application are accessing the TaskService from a service class of our own.  
One such implementations where the error is being thrown.  
The stack trace catches the exception at this line:

taskService.completeTaskWithForm(taskId, completeTaskFormRepresentation.getFormId(),  
completeTaskFormRepresentation.getOutcome(), completeTaskFormRepresentation.getValues());

 ![10%20AM](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/c/cedbee0b26ff3bd49be7a8a500823c6909b7d45a.png)

---

<div class="post-metadata">

**Author:** ![mmva2142](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@mmva2142](https://forum.flowable.org/u/mmva2142)\
**Post date:** [September 1, 2019, 11:12am UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/4 "2019-09-01T11:12:08Z")

</div>

> [@Sruni5](#):
>
> TaskEntity

I think two different class loaders are trying to load the task and you are getting this error. In java, if two class loaders get the same entity, they are actually treated as entirely different entities. can you reply the result of [Class.getClassLoader()](https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getClassLoader%28%29) on the task you defined and the interface?

---

<div class="post-metadata">

**Author:** ![Sruni5](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Sruni5](https://forum.flowable.org/u/Sruni5)\
**Post date:** [September 3, 2019, 2:46am UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/5 "2019-09-03T02:46:20Z")

</div>

Here is the result of class.getClassLoader on the task object:

org.springframework.boot.devtools.restart.classloader.RestartClassLoader

---

<div class="post-metadata">

**Author:** ![mmva2142](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@mmva2142](https://forum.flowable.org/u/mmva2142)\
**Post date:** [September 3, 2019, 3:18am UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/6 "2019-09-03T03:18:41Z")

</div>

Can you provide your code if possible?  
Thanks. it’s a little hard to debug it on my side

---

<div class="post-metadata">

**Author:** ![Sruni5](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Sruni5](https://forum.flowable.org/u/Sruni5)\
**Post date:** [September 3, 2019, 4:12am UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/7 "2019-09-03T04:12:42Z")

</div>

I can provide screenshots of the code implementation where the error is being thrown. I hope this helps.  
I am using SpringBoot 2.0.3 and flowable engine 6.5.0

On calling the Api defined by the first method, add(@RequestBody CasePostRequestDTO casePostRequestDTO), in the code, a process instance is initiated on that case object.  
The controller calls go to a CaseServicer class which makes calls to the methods defined in our FlowableService class. This FlowableService Class does not extend or implement any other classes/interfaces, but is Autowired to the required service classes (BpmnService, TaskService, FormService etc.)  
The exception is thrown when a call is made to the Api defined over the second method in the controller, updateCase(@PathVariable Long caseId, @RequestBody CaseFormRequestDTO caseFormRequestDTO), where I am attempting to complete the current task.

 ![Controller%20Code](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/0/04b799b4596257c9411251b8e91035c9f4da46b5.png)

---

<div class="post-metadata">

**Author:** ![Sruni5](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Sruni5](https://forum.flowable.org/u/Sruni5)\
**Post date:** [September 3, 2019, 4:13am UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/8 "2019-09-03T04:13:06Z")

</div>

CaseService class

 ![Service%20Code](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/5/5caeff3a242b3d8121657d8748f084d4fd5a01d7.png)

---

<div class="post-metadata">

**Author:** ![Sruni5](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Sruni5](https://forum.flowable.org/u/Sruni5)\
**Post date:** [September 3, 2019, 4:15am UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/9 "2019-09-03T04:15:33Z")

</div>

FlowableService class where the final exception is thrown at line 168

 ![FlowableService](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/5/514f216a91d2e858123de4d8bdc83ca7bf0e3d5e.png)

If this is not clear allow me to figure out how better to share the code.

Thank you for your help!

---

<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:** [September 3, 2019, 6:30am UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/10 "2019-09-03T06:30:17Z")

</div>

@mmva2142 this happens only during development right? We’ve had issues with the spring-devtools and the entities classes not being properly reloaded. I think it might be somehow linked to MyBatis. I would advise you to remove the spring-devtools from your project (at least for the time being).

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![akki](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@akki](https://forum.flowable.org/u/akki)\
**Post date:** [September 3, 2019, 6:48am UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/11 "2019-09-03T06:48:41Z")

</div>

Hi @Sruni5,

Why not autowire the taskService since by default all flowable services are available as beans?  
If you just want to complete the task there is a simpler way, which I tried before using the taskService, claim the task with proper user id and then complete it by providing variable values.

---

<div class="post-metadata">

**Author:** ![Sruni5](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Sruni5](https://forum.flowable.org/u/Sruni5)\
**Post date:** [September 3, 2019, 7:15pm UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/12 "2019-09-03T19:15:38Z")

</div>

@mmva2142 @filiphr I switched to version 6.5.0 from 6.5.0-SNAPSHOT and it is no longer throwing the exception. I was unable to resolve the issue using 6.5.0-SNAPSHOT. I removed spring-devtools and that resulted in bean creation errors so did not continue with that approach.

Thank you!

---

<div class="post-metadata">

**Author:** ![Sruni5](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Sruni5](https://forum.flowable.org/u/Sruni5)\
**Post date:** [September 3, 2019, 7:18pm UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/13 "2019-09-03T19:18:14Z")

</div>

@akki The code is using the Autowired TaskService bean. It has been implemented the same way you have described.

Thanks!

---

<div class="post-metadata">

**Author:** ![mmva2142](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@mmva2142](https://forum.flowable.org/u/mmva2142)\
**Post date:** [September 4, 2019, 6:11am UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/14 "2019-09-04T06:11:50Z")

</div>

Interesting, I’m glad it resolved the issue, I do apologize if i wasn’t of any help. I read your screen shots many times and didn’t see anything wrong with it.

---

<div class="post-metadata">

**Author:** ![Sruni5](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Sruni5](https://forum.flowable.org/u/Sruni5)\
**Post date:** [September 4, 2019, 6:17pm UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/15 "2019-09-04T18:17:24Z")

</div>

No worries! It most likely is being caused by multiple class loaders as you had mentioned. I dug deeper and noticed that both AppClassLoader and RestartClassLoader were being used at different points. Removing the spring-devtools dependency may have worked but it resulted in other errors. Everything is running smoothly on 6.5.0 however.

Thank you for the help!

---

<div class="post-metadata">

**Author:** ![mmva2142](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@mmva2142](https://forum.flowable.org/u/mmva2142)\
**Post date:** [September 14, 2019, 10:46am UTC](https://forum.flowable.org/t/error-when-trying-to-access-a-task-within-the-code-java-lang-classcastexception-org-flowable-task-service-impl-persistence-entity-taskentityimpl-cannot-be-cast-to-org-flowable-task-service-impl-persistence-entity-taskentity/4430/16 "2019-09-14T10:46:42Z")

</div>

Glad it has been resolved.  
Cheers.
