1 Reply Latest reply on Mar 2, 2007 6:26 AM by M K

    Insert TaskNode and Task at runtime via an ActionHandler

    M K Newbie

      Hello,

      I am trying to insert a new TaskNode together with a Task and a TaskInstance into a ProcessInstance at run-time through an ActionHandler. When testing it through the Jbpm API it executes fine but after deploying the process i get a TransientObjectException.

      The code looks like this:

      
      
      public class MyActionHandler implements ActionHandler {
      [...]
      public void execute(ExecutionContext executionContext) throws Exception {
      [...]
       TaskNode insertedTaskNode = new TaskNode("Check Task");
      
       TaskMgmtDefinition tmd = (TaskMgmtDefinition)
       executionContext.getDefinition(TaskMgmtDefinition.class);
       Task task = new Task("Check please");
       TaskInstance taskInstance = processInstance.getTaskMgmtInstance().createTaskInstance(task,
       processInstance.getRootToken());
       taskInstance.setActorId("grover");
       Node currentNode = executionContext.getNode();
      
      
       // TODO: Auch mehrere berücksichtigen!
       Transition currentNodeLeavingTransition = (Transition) currentNode.getLeavingTransitions().get(0);
       Node nextNode = currentNodeLeavingTransition.getTo();
      
       currentNodeLeavingTransition.setTo(insertedTaskNode);
      
       Transition insertedTaskNodeLeavingTransition = new Transition("insertedTaskNodeLeavingTransition");
       insertedTaskNodeLeavingTransition.setFrom(insertedTaskNode);
       insertedTaskNodeLeavingTransition.setTo(nextNode);
      
      
       insertedTaskNode.addTask(task);
      [...]
      }
      [...]
      }


      The error stack looks like that:
      15:23:54,813 DEBUG [HibernateSaveOperation] saving process instance
      15:23:54,813 DEBUG [SaveLogsOperation] flushing logs to logging service.
      15:23:54,823 DEBUG [CascadeSaveOperation] cascading save of 'org.jbpm.graph.exe.ProcessInstance@579615'
      15:23:54,823 INFO [[/jbpm]] WARNING: Component _id13 just got an automatic id, because there was no id assigned yet. If this comp
      onent was created dynamically (i.e. not by a JSP tag) you should assign it an explicit static id or assign it the id you get from
      the createUniqueId from the current UIViewRoot component right after creation!
      15:23:54,833 ERROR [TaskMgmtSession] org.hibernate.TransientObjectException: object references an unsaved transient instance - sav
      e the transient instance before flushing: org.jbpm.taskmgmt.def.Task
      15:23:54,833 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
      javax.faces.el.EvaluationException: Cannot get value for expression '#{homeBean.taskInstances}'
      at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:399)
      at javax.faces.component.UIData.getValue(UIData.java:779)
      at javax.faces.component.UIData.createDataModel(UIData.java:545)
      at javax.faces.component.UIData.getDataModel(UIData.java:534)
      at javax.faces.component.UIData.getRowCount(UIData.java:103)
      at org.apache.myfaces.renderkit.html.HtmlTableRendererBase.encodeInnerHtml(HtmlTableRendererBase.java:124)
      at org.apache.myfaces.renderkit.html.HtmlTableRendererBase.encodeChildren(HtmlTableRendererBase.java:94)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:319)
      at javax.faces.webapp.UIComponentTag.encodeChildren(UIComponentTag.java:343)
      at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:251)
      at org.apache.myfaces.taglib.UIComponentBodyTagBase.doEndTag(UIComponentBodyTagBase.java:55)
      at org.apache.jsp.home_jsp._jspx_meth_h_dataTable_0(org.apache.jsp.home_jsp:205)
      at org.apache.jsp.home_jsp._jspx_meth_f_view_0(org.apache.jsp.home_jsp:124)
      at org.apache.jsp.home_jsp._jspService(org.apache.jsp.home_jsp:76)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
      at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:415)
      at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:234)
      at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:300)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:95)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jbpm.webapp.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:56)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jbpm.web.JbpmContextFilter.doFilter(JbpmContextFilter.java:83)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jbpm.webapp.filter.LogFilter.doFilter(LogFilter.java:59)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.faces.el.EvaluationException: org.jbpm.webapp.bean.HomeBean
      at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:78)
      at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:532)
      at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
      at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:380)
      ... 57 more
      Caused by: javax.faces.el.EvaluationException: Bean: org.jbpm.webapp.bean.HomeBean, property: taskInstances
      at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:404)
      at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:71)
      ... 60 more
      Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:400)
      ... 61 more
      Caused by: org.jbpm.JbpmException: couldn't get task instances list for actor 'grover'
      at org.jbpm.db.TaskMgmtSession.findTaskInstances(TaskMgmtSession.java:63)
      at org.jbpm.webapp.bean.HomeBean.getTaskInstances(HomeBean.java:49)
      ... 66 more
      Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance b
      efore flushing: org.jbpm.taskmgmt.def.Task
      at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
      at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
      at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:221)
      at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:476)
      at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:2802)
      at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:457)
      at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:180)
      at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:104)
      at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
      at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76
      )
      at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
      at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:878)
      at org.hibernate.impl.SessionImpl.prepareQueries(SessionImpl.java:1071)
      at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1061)
      at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1010)
      at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
      at org.jbpm.db.TaskMgmtSession.findTaskInstances(TaskMgmtSession.java:59)
      ... 67 more
      15:23:54,833 DEBUG [JbpmContext] closing JbpmContext


      Thanks for your help.
      Regards,
      Maurice