I’m trying to implement the ‘afterUpdate’ event handler. Here is my code (method signature generated by the console): @Asset( “SignalsTest” )
public class SignalsTestTableEventHandler extends com.backendless.servercode.extension.PersistenceExtender
{ @Override
public void afterUpdate( RunnerContext context, SignalsTest signalstest, ExecutionResult result ) throws Exception
{
int i = 666;
}
}
When I make an update to an object in the table I get the following error:
BackendlessErrorDomain Code=0 “class java.util.HashMap cannot be cast to class com.helpapaw.models.SignalsTest (java.util.HashMap is in module java.base of loader ‘bootstrap’; com.helpapaw.models.SignalsTest is in unnamed module of loader java.net.URLClassLoader @62ddd21b)” UserInfo={NSLocalizedDescription=class java.util.HashMap cannot be cast to class com.helpapaw.models.SignalsTest (java.util.HashMap is in module java.base of loader ‘bootstrap’; com.helpapaw.models.SignalsTest is in unnamed module of loader java.net.URLClassLoader @62ddd21b)}
Looks like the method signature or the object passed to the method is of the wrong type.
I was able to reproduce this problem in my own app. Internal ticket BKNDLSS-22671 was created for it. We will notify you when it will be fixed. As temporary bypass you can remove model classes mappins for this table and work directly with Map instances.
Sorry for inconvenience.
Unfortunately, the fix is not working for me. I downloaded a new project from the console and added a single line in the afterUpdate method so I can put a breakpoint: @Override
public void afterUpdate( RunnerContext context, SignalsTest signalstest, ExecutionResult result ) throws Exception
{
// add your code here
int i = 666;
}
After updating a row in the SignalsTest table I still get the following error:
InvocationTask[ appId:BDCD56B9-351A-E067-FFA4-9EA9CF2F4000 ]\n Exception: java.lang.ClassCastException: class java.util.HashMap cannot be cast to class com.helpapaw.models.SignalsTest (java.util.HashMap is in module java.base of loader ‘bootstrap’; com.helpapaw.models.SignalsTest is in unnamed module of loader java.net.URLClassLoader @5ee34b1b)\n\tat com.helpapaw.events.persistence_service.SignalsTestTableEventHandler.afterUpdate(SignalsTestTableEventHandler.java:26)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.base/java.lang.reflect.Method.invoke(Method.java:564)\n\tat com.backendless.coderunner.runtime.task.EventInvocationTask.runImpl(EventInvocationTask.java:114)\n\tat com.backendless.coderunner.runtime.executor.ExtendedRunnable.run(ExtendedRunnable.java:38)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)\n\tat java.base/java.lang.Thread.run(Thread.java:832)\n
If I disable the afterUpdate event handler from the console the operation passes without error.
Sorry for delay with response. I checked your case and found that error present only when both, beforeUpdate and afterUpdate, handlers are present for update action. When there is only one of them is present then everything works as expected. It caused by bug in handlers arguments typecast logic.
I have created internal ticket for this problem BKNDLSS-23042. We write you back when fix will be released. As bypass you can again return to maps instead of classes.
Sorry for inconvenience.