AnsweredAssumed Answered

Exception appears when put serializable variable to Activiti execution

Question asked by mrgrechkinn on Mar 24, 2014
I have a problem with activiti and execution variables. I'm add java hash map to execution variable from javascript and exceptions appears:



var reportParams = new java.util.HashMap();
reportParams["user"] = String("user");
reportParams["nodeRef"] = String(someNode.nodeRef);
execution.setVariable("reportParams", reportParams);



I can put map to execution variable because we have org.activiti.engine.impl.variable.SerializableType and HashMap will be serialized to byte array and it's works fine.
Also I have a java code that reads this variable and use it:



Map<String, String> reportParams = (HashMap<String, String>) execution.getVariable("reportParams");



And this works fine too. But I have a problem when I'm going to my dashboard, my tasks dashlet trying to get my tasks and without success;
Logs:
16:47:44,453 ERROR org.springframework.extensions.webscripts.AbstractRuntime Exception from executeScript - redirecting to status template error: 02210040 Wrapped Exception (with status template):
Error updating database.  Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
The error may involve org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.updateByteArray-Inline
The error occurred while setting parameters
Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
org.springframework.extensions.webscripts.WebScriptException: 02210040 Wrapped Exception (with status template):
Error updating database.  Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
The error may involve org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.updateByteArray-Inline
The error occurred while setting parameters
Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
   at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1067)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
   at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:410)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:401)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:479)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:517)
   at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:333)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:377)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
   at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
   at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.ibatis.exceptions.PersistenceException:
Error updating database.  Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
The error may involve org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.updateByteArray-Inline
The error occurred while setting parameters
Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
   at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:120)
   at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:433)
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:348)
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:147)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:103)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)
   at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
   at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
   at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
   at org.activiti.engine.impl.TaskServiceImpl.getVariables(TaskServiceImpl.java:172)
   at org.alfresco.repo.workflow.activiti.properties.ActivitiPropertyConverter.getTaskProperties(ActivitiPropertyConverter.java:121)
   at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.getTaskProperties(ActivitiTypeConverter.java:445)
   at org.alfresco.service.cmr.workflow.LazyActivitiWorkflowTask.ensureProperties(LazyActivitiWorkflowTask.java:131)
   at org.alfresco.service.cmr.workflow.LazyActivitiWorkflowTask$LazyPropertiesMap.get(LazyActivitiWorkflowTask.java:212)
   at org.alfresco.service.cmr.workflow.LazyActivitiWorkflowTask$LazyPropertiesMap.get(LazyActivitiWorkflowTask.java:150)
   at org.alfresco.repo.web.scripts.workflow.WorkflowModelBuilder.isPooled(WorkflowModelBuilder.java:400)
   at org.alfresco.repo.web.scripts.workflow.WorkflowModelBuilder.buildSimple(WorkflowModelBuilder.java:195)
   at org.alfresco.repo.web.scripts.workflow.TaskInstancesGet.buildModel(TaskInstancesGet.java:187)
   at org.alfresco.repo.web.scripts.workflow.AbstractWorkflowWebscript.executeImpl(AbstractWorkflowWebscript.java:80)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:64)
   … 25 more
Caused by: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
   at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1279)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
   at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:22)
   at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:51)
   at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:29)
   at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:87)
   at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:46)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:118)
   … 45 more

After some debug I found that is a problem with byte array (my hash map):
An exception appears in org.activiti.engine.impl.db.DbSqlSession:
In next line we get objects to update

public void flush() {

List<PersistentObject> updatedObjects = getUpdatedObjects();

}

In next line we trying to equals byte arrays from cache and db. But we can't equals byte arrays in same way:

public List<PersistentObject> getUpdatedObjects() {

Object originalState = cachedObject.getPersistentObjectState();
if (!originalState.equals(persistentObject.getPersistentState())) {
  updatedObjects.add(persistentObject);
} else {
  log.finest("loaded object '"+persistentObject+"' was not updated");
}

}

And in next method we trying to update variable and it's fall with exception

protected void flushUpdates(List<PersistentObject> updatedObjects) {
}

Outcomes