AnsweredAssumed Answered

SQL exception when using complex process variables

Question asked by franck102 on Jan 24, 2014
Latest reply on Jan 24, 2014 by franck102
I am getting a foreign key violation exception when Activiti is trying to log the value of my complex variables to the database. This happens in DbSqlSession#flushInserts, and debugging shows that the statements to insert the serialized content into the byte array table come after the statement that references it in the local insertedObjects field that the method is looping over.

In the dump below variable id=4745 is the second statement but it comes before ByteArrayEntity id=4751 it refers to, the the insert fails.

Any suggestion as to what may be causing this? Thanks!


insertedObjects=
ProcessInstance[4744],
VariableInstanceEntity[id=4745, name=initiator, type=serializable, byteArrayValueId=4751],
HistoricVariableInstanceEntity[id=4745, name=initiator, type=serializable, byteArrayValueId=4752],
IdentityLinkEntity[id=4746, type=starter, userId=june, processInstanceId=4744],
org.activiti.engine.impl.persistence.entity.HistoricIdentityLinkEntity@40044be8, HistoricProcessInstanceEntity[superProcessInstanceId=null],
HistoricActivityInstanceEntity[activityId=sid-4C7C5325-DABF-4ADD-9AA0-FC9B5B6B33D3, activityName=null],
ByteArrayEntity[id=4748, name=var-asset, size=9561],
VariableInstanceEntity[id=4749, name=asset, type=serializable, byteArrayValueId=4748],
ByteArrayEntity[id=4750, name=hist.var-asset, size=9561],
HistoricVariableInstanceEntity[id=4749, name=asset, type=serializable, byteArrayValueId=4750],
ByteArrayEntity[id=4751, name=var-initiator, size=600],
ByteArrayEntity[id=4752, name=hist.var-initiator, size=600],
HistoricActivityInstanceEntity[activityId=sid-A8604028-D517-4A46-8069-8C173AF62633, activityName=Notify Approvers],
HistoricActivityInstanceEntity[activityId=sid-4635F0C0-B76A-4EC7-B995-2EDF55BE1E3E, activityName=Approve Model],
Task[id=4755, name=Approve Model],
org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity@5a138d2d, IdentityLinkEntity[id=4756, type=candidate, groupId=mcentral-admin, taskId=4755],
org.activiti.engine.impl.persistence.entity.HistoricIdentityLinkEntity@3999b38e]


The complete stack trace is:


[[14-01-24 09:32:26] WARN  [http-bio-8080-exec-5] .C.MCActivitiRestServicesApplication  Exception or error caught in resource org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_bytearray"
  Detail: Key (bytearray_id_)=(4738) is not present in table "act_ge_bytearray".
### The error may involve org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.insertVariableInstance-Inline
### The error occurred while setting parameters
### SQL: insert into ACT_RU_VARIABLE (ID_, REV_,     TYPE_, NAME_, PROC_INST_ID_, EXECUTION_ID_, TASK_ID_, BYTEARRAY_ID_,     DOUBLE_, LONG_ , TEXT_, TEXT2_)     values (     ?,     1,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?     )
### Cause: org.postgresql.util.PSQLException: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_bytearray"
  Detail: Key (bytearray_id_)=(4738) is not present in table "act_ge_bytearray".
   at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:150)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:137)
   at org.activiti.engine.impl.db.DbSqlSession.flushInserts(DbSqlSession.java:540)
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:443)
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:170)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:117)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:66)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:37)
   at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
   at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
   at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceByKey(RuntimeServiceImpl.java:68)
   at org.activiti.rest.service.api.runtime.process.ProcessInstanceCollectionResource.createProcessInstance(ProcessInstanceCollectionResource.java:132)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:601)
   at org.restlet.resource.ServerResource.doHandle(ServerResource.java:449)
   at org.restlet.resource.ServerResource.post(ServerResource.java:1114)
   at org.restlet.resource.ServerResource.doHandle(ServerResource.java:533)
   at org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource.java:590)
   at org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java:302)
   at org.restlet.resource.ServerResource.handle(ServerResource.java:849)
   at org.restlet.resource.Finder.handle(Finder.java:513)
   at org.restlet.routing.Filter.doHandle(Filter.java:159)
   at org.restlet.routing.Filter.handle(Filter.java:206)
   at org.restlet.routing.Router.doHandle(Router.java:500)
   at org.restlet.routing.Router.handle(Router.java:740)
   at org.restlet.routing.Filter.doHandle(Filter.java:159)
   at org.restlet.routing.Filter.handle(Filter.java:206)
   at org.restlet.routing.Filter.doHandle(Filter.java:159)
   at org.restlet.routing.Filter.handle(Filter.java:206)
   at org.restlet.routing.Filter.doHandle(Filter.java:159)
   at org.restlet.routing.Filter.handle(Filter.java:206)
   at org.restlet.routing.Filter.doHandle(Filter.java:159)
   at org.restlet.routing.Filter.handle(Filter.java:206)
   at org.restlet.routing.Filter.doHandle(Filter.java:159)
   at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:155)
   at org.restlet.routing.Filter.handle(Filter.java:206)
   at org.restlet.routing.Filter.doHandle(Filter.java:159)
   at org.restlet.routing.Filter.handle(Filter.java:206)
   at org.restlet.engine.ChainHelper.handle(ChainHelper.java:114)
   at org.restlet.engine.application.ApplicationHelper.handle(ApplicationHelper.java:75)
   at org.restlet.Application.handle(Application.java:391)
   at org.restlet.routing.Filter.doHandle(Filter.java:159)
   at org.restlet.routing.Filter.handle(Filter.java:206)
   at org.restlet.routing.Router.doHandle(Router.java:500)
   at org.restlet.routing.Router.handle(Router.java:740)
   at org.restlet.routing.Filter.doHandle(Filter.java:159)
   at org.restlet.routing.Filter.handle(Filter.java:206)
   at org.restlet.routing.Router.doHandle(Router.java:500)
   at org.restlet.routing.Router.handle(Router.java:740)
   at org.restlet.routing.Filter.doHandle(Filter.java:159)
   at org.restlet.routing.Filter.handle(Filter.java:206)
   at org.restlet.engine.ChainHelper.handle(ChainHelper.java:114)
   at org.restlet.Component.handle(Component.java:391)
   at org.restlet.Server.handle(Server.java:491)
   at org.restlet.engine.ServerHelper.handle(ServerHelper.java:74)
   at org.restlet.engine.http.HttpServerHelper.handle(HttpServerHelper.java:153)
   at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:1031)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
   at org.eclipse.virgo.web.tomcat.support.ApplicationNameTrackingValve.invoke(ApplicationNameTrackingValve.java:33)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
   at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
   at java.lang.Thread.run(Thread.java:722)
Caused by: org.postgresql.util.PSQLException: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_bytearray"
  Detail: Key (bytearray_id_)=(4738) is not present in table "act_ge_bytearray".
   at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
   at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836)
   at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:381)
   at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:601)
   at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:55)
   at $Proxy157.execute(Unknown Source)
   at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:41)
   at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:66)
   at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:45)
   at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:100)
   at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:148)
   … 76 common frames omitted


Outcomes