7 Replies Latest reply on Jul 30, 2007 7:42 PM by i,bigfoot

    Cannot save process instance? (from a NEWBIE!!)

    i,bigfoot

      Hi.

      I am trying to get a simple process deployed into a web application just to get started with jBPM.

      The process archive deploys into the database fine, and first time around I can create a process instance and then save it. However, when i create a process instance for a second time (I might be making a fundamental error here) I cannot save it again.

      Offending code

       public ActionForward execute(ActionMapping pMapping,
       ActionForm pActionForm, HttpServletRequest pRequest,
       HttpServletResponse pResponse) throws Exception {
      
       // the configuration instance is retrieved in a static block in this class
       // using the default jbpm.cfg.xml
       JbpmConfiguration cfg = JbpmUtil.getJbpmConfiguration();
       JbpmContext ctx = cfg.createJbpmContext();
      
       try {
       if (log.isDebugEnabled()) {
       log.debug("Creating a JBPM Process");
       }
      
       GraphSession graphSession = ctx.getGraphSession();
      
       ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("ProposalToOrder");
      
       if( processDefinition != null ) {
       log.info("Process Definition is ["+processDefinition.getName()+"/"+processDefinition.getVersion()+"/"+processDefinition.getId()+"]");
      
       log.info("Creating process instance");
       // create new process instance
       ProcessInstance processInstance = processDefinition.createProcessInstance();
       processInstance.signal();
       // attempt to save causes SQL constraint violation ?? (second pass only)
       ctx.save(processInstance);
       }
      
      
       } catch (Exception e) {
       return pMapping.findForward(ApplicationConstants.FORWARD_SYSTEM_ERROR);
       } finally {
       ctx.close();
       }
       return pMapping.findForward("success");
       }
      


      using process definition
      <?xml version="1.0" encoding="UTF-8"?>
      
      <process-definition
       xmlns="urn:jbpm.org:jpdl-3.2" name="ProposalToOrder">
       <start-state name="beginState">
       <transition name="transitionToTask" to="firstTask"></transition>
       </start-state>
       <end-state name="endState"></end-state>
       <task-node name="firstTask">
       <transition name="transitionToDecision" to="decisionYesNo"></transition>
       </task-node>
       <decision name="decisionYesNo">
       <transition name="No" to="NoState"></transition>
       <transition name="Yes" to="endState"></transition>
       </decision>
       <state name="NoState">
       <transition name="goToEnd" to="endState"></transition>
       </state>
      </process-definition>
      


      incredibly frustrating stack trace...

      2007-07-30 14:09:08,081 INFO [STDOUT] Hibernate:
      /* insert org.jbpm.graph.exe.ProcessInstance
      */ insert
      into
      JBPM_PROCESSINSTANCE
      (VERSION_, KEY_, START_, END_, ISSUSPENDED_, PROCESSDEFINITION_, ROOTTOKEN_, SUPERPROCESSTOKEN_, ID_)
      values
      (?, ?, ?, ?, ?, ?, ?, ?, ?)
      2007-07-30 14:09:08,091 DEBUG [org.hibernate.jdbc.AbstractBatcher] Executing batch size: 1
      2007-07-30 14:09:08,101 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
      2007-07-30 14:09:08,101 DEBUG [org.hibernate.util.JDBCExceptionReporter] Could not execute JDBC batch update [/* insert org.jbpm.graph.exe.ProcessInstance */ insert into JBPM_PROCESSINSTANCE (VERSION_, KEY_, START_, END_, ISSUSPENDED_, PROCESSDEFINITION_, ROOTTOKEN_, SUPERPROCESSTOKEN_, ID_) values (?, ?, ?, ?, ?, ?, ?, ?, ?)]
      java.sql.BatchUpdateException: ORA-00001: unique constraint (OES_JBPM.SYS_C0010738) violated

      at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:342)
      at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
      at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
      at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
      at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:91)
      at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:86)
      at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:171)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2048)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
      at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
      at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
      at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
      at org.jbpm.persistence.db.DbPersistenceService.commit(DbPersistenceService.java:253)
      at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:211)
      at org.jbpm.svc.Services.close(Services.java:222)
      at org.jbpm.JbpmContext.close(JbpmContext.java:139)
      at com.salestech.action.CreateProcessAction.execute(Unknown Source)
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      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.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      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.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      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:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      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)
      2007-07-30 14:09:08,101 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 1, SQLState: 23000
      2007-07-30 14:09:08,111 ERROR [org.hibernate.util.JDBCExceptionReporter] ORA-00001: unique constraint (OES_JBPM.SYS_C0010738) violated

      2007-07-30 14:09:08,111 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 1, SQLState: 23000
      2007-07-30 14:09:08,111 ERROR [org.hibernate.util.JDBCExceptionReporter] ORA-00001: unique constraint (OES_JBPM.SYS_C0010738) violated


      Can anyone help here? I assume that I can create to process instances from the same process definition?? I have attempted this in a number of different ways, examples found in package documentation, wiki and elsewhere on the web.. in all cases this same behaviour occurs.

      Is the process definition incomplete? I thought to leave it this simple for starters would be easier to get this going first time... seems i was wrong about that too :-)
      I am pretty stuck now as I don't really know where to go from here.

      Cheers,
      Troy

        • 1. Re: Cannot save process instance? (from a NEWBIE!!)
          i,bigfoot


          Further info...

          The constraint SYS_C0010738 is a Unique constraint on two columns in the ProcessInstance table.. KEY_ and PROCESSDEFINITION_

          This leads to further confusion as the field PROCESSDEFINTION_ also participates in a foreign key relationship with the PROCESSDEFINITION table field ID. This suggests that there needs to be a new process definition for every new process instance??

          Again, not sure if I am getting the idea of this.. still hoping that someone might be able to point me in the right direction.

          Cheers,
          Troy

          • 2. Re: Cannot save process instance? (from a NEWBIE!!)
            masipu

            try using this code:

            ProcessInstance process = ctx.newProcessInstance("ProposalToOrder");
            


            instead of creating graphsession etc..

            • 3. Re: Cannot save process instance? (from a NEWBIE!!)
              i,bigfoot


              Hi Masipu..
              thx for reply, unfortunately this still doesn't work.

              The same stack trace is produced as shown previously.
              I can see that it is trying to create a new process instance, the hibernate logging shows the INSERT statement that is failing. I just dont understand why it has created the unique constraint on these fields ??

              Is this normal, could my database be corrupt / incorrect some how?

              Cheers,
              Troy

              • 4. Re: Cannot save process instance? (from a NEWBIE!!)
                masipu

                Sorry but I can't help any further. Maybe you should ask this from hibernate forum..

                • 5. Re: Cannot save process instance? (from a NEWBIE!!)
                  i,bigfoot


                  Thanks anyways masipu..

                  I have removed the unique constraint on the foreign key value and my problem has gone away...

                  however, i created this schema using the JbpmConfiguration.createSchema() method, so i am very reluctant to assume that deleting constraints that were created by this method call would be the appropriate fix for my problem.

                  Tho in saying this, I cannot see why this constraint existed on this field? If anyone had any further insight on this I would love to hear about it!

                  Cheers,
                  Troy

                  • 6. Re: Cannot save process instance? (from a NEWBIE!!)
                    robhadfield

                    Hi, you don't say which version you're using, but in the upgrade to 3.2.1 a 3rd constructor was added to ProcessInstance that lets you specify a business key. Specify this (proposal number? order number?) as appropriate for your application and you should be OK.

                    • 7. Re: Cannot save process instance? (from a NEWBIE!!)
                      i,bigfoot

                      Hi robhadfield.

                      You are correct, didn't mention any version at all.. DOH! You guessed right it is 3.2.1 and the solution you have proposed not only worked, but also provides a good handle for the next part of the problem.
                      I was trying to create the ProcessInstance using either the JbpmContext or the GraphSession objects, didn't realise you could create it off the ProcessDefintion as well.

                      Thanks heaps!

                      Troy