3 Replies Latest reply on Apr 8, 2009 5:44 AM by Ramon Wang

    Is that possible to create a non-persisted ProcessInstance i

    Ramon Wang Newbie

      The question is that I want to create a new ProcessInstance inside an outer ProcessInstance, actually this creation (new) operation is done in the ActionHandler of the outer ProcessInstance, the key is that the outer one is a persisted one, but I don't want the inner one to be persisted. So I got the following exception when I try to close the jbpmContext:

      org.hibernate.TransientObjectException: object references an unsaved transient instance - save the t
      ransient instance before flushing: org.jbpm.graph.def.Node
      at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
      at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
      at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:242)
      at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:597)
      at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.
      java:3128)


      The code is as below:
      The outer one:
      JbpmContext jbpmContext = JbpmConfingurationFactory.jbpmConfiguration
       .createJbpmContext();
       try {
       ...
       ProcessInstance processInstance = new ProcessInstance(retrievedPd);
       jbpmContext.save(processInstance);
       }
       } finally {
       jbpmContext.close(); //where I get the exception
       }
      
      


      One ActionHandler of the outer one which expect to create a new ProcessInstance:
      public void execute(ExecutionContext executionContext) throws Exception {
       // get operation context from workflow
       OperationContext context = (OperationContext) executionContext
       .getContextInstance().getTransientVariable(
       Operation.OPERATION_CONTEXT);
       // create discovery operation
       WorkflowOperation discoveryOperation = new WorkflowOperation(context);
       // create discovery related workflow
       ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(definition);
       ProcessInstance processInstance =
       new ProcessInstance(processDefinition);
       ....
      


      Can anybody tell me why I got this error, is there any possible workaround?

        • 1. Re: Is that possible to create a non-persisted ProcessInstan
          Volker Börchers Newbie

          Have you tried to remove the offending object(s) from the Hibernate session? I don't know if it is possible to access it in the right moment but I would try

          jbpmContext.getSession().evict(processInstance)
          (or the like)

          BTW: Doesn't it help to omit the call to jbpmContext.save() ?

          Volker

          • 2. Re: Is that possible to create a non-persisted ProcessInstan
            Ramon Wang Newbie

             

            "boercher" wrote:
            Have you tried to remove the offending object(s) from the Hibernate session? I don't know if it is possible to access it in the right moment but I would try
            jbpmContext.getSession().evict(processInstance)
            (or the like)

            BTW: Doesn't it help to omit the call to jbpmContext.save() ?

            Volker


            Hi Volker, I will try it, but it sounds like a hack? It seems I can and JBPM provides the ability to specify what process instances should be saved and what shouldn't.

            • 3. Re: Is that possible to create a non-persisted ProcessInstan
              Ramon Wang Newbie

              Hi Volker

              Unfortunately, your hack doesn't work, I got a more serious exception:

              17:41:04,598 ERROR [AssertionFailure] an assertion failure occured (this may indicate a bug in Hiber
              nate, but is more likely due to unsafe use of the session)
              org.hibernate.AssertionFailure: possible nonthreadsafe access to session
               at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:64)
               at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
               at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
               at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
               at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingE
              ventListener.java:298)
               at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:
              27)