5 Replies Latest reply on May 14, 2010 10:10 PM by HuiSheng Xu

    [JBPM 4] Process variable

    Pawel Janusz Newbie

      === Environment ==============================
      - jBPM Version : 4
      - Database : Oracle 10g XE
      - JDK : 1.5
      - Container : standalone App
      - Configuration : standard JBPM 4, changed jbpm.hibernate.cfg.xml, added line for Hibernate entity mapping class:
      <mapping resource="pl/test/jbpm/entity/Persisted.hbm.xml" />

      === Process ==================================
      Process from example: Comments

      === API ===================================
      ExecutionService executionService = procEngine.getExecutionService();

      Map<String, Object> variables = new HashMap<String, Object>();
      Persisted p = new Persisted();
      p.setName("Variable");
      p.setValue("Value");

      SessionFactory sf = procEngine.get(SessionFactory.class);
      Session sess = sf.openSession();
      sess.beginTransaction();
      sess.save(p);
      sess.flush();
      sess.getTransaction().commit();

      variables.put("content", "java");

      ProcessInstance processInstance = executionService.startProcessInstanceByKey("TaskVariables", variables);
      executionService.setVariable(processInstance.getId(), "persistence", p);

      === Stacktrace ==============================
      Exception in thread "main" org.hibernate.HibernateException: instance not of expected entity type: org.jbpm.pvm.internal.type.variable.UnpersistableVariable is not a: org.jbpm.pvm.internal.type.Variable
      at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassEntityPersister(AbstractEntityPersister.java:3663)
      at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1374)
      at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:203)
      at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:535)
      at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:103)
      at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
      at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:534)
      at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:526)
      at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:241)
      at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:291)
      at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:239)
      at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:192)
      at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:319)
      at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:265)
      at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:242)
      at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:192)
      at org.hibernate.engine.Cascade.cascade(Cascade.java:153)
      at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:154)
      at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:145)
      at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
      at org.jbpm.pvm.internal.tx.HibernateSessionResource.prepare(HibernateSessionResource.java:54)
      at org.jbpm.pvm.internal.tx.StandardTransaction.commit(StandardTransaction.java:106)
      at org.jbpm.pvm.internal.tx.StandardTransaction.complete(StandardTransaction.java:65)
      at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:61)
      at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:54)
      at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
      at org.jbpm.pvm.internal.svc.ExecutionServiceImpl.setVariable(ExecutionServiceImpl.java:145)
      at pl.test.jbpm.Main.main(Main.java:63)

      === Debug logs ==============================
      [ScopeInstanceImpl] create variable 'persistence-id' in 'execution[TaskVariables.342]' with value 'pl.test.jbpm.entity.Persisted@970c0e'

      === Problem description =========================
      Persistent is a hibernate entity class (configured using XML). The problem is when i'm trying to set hibernate entity as process variable i got exception as above :(
      I have no problem to store simple variable as String or Long or even as Serializable class, but for my application i have to store variable as whole entity (in table in DB).
      Can You help me with my problem? Did i missed some configuration? Maybe anyone can point complete example of store process variable in DB table ?

      Thanks
      Czujnik

        • 1. Re: [JBPM 4] Process variable
          Sebastian Schneider Master

          I am not very proficient in this field but my hint would be to take a look at jbpm.variable.types.xml. In the source I even read something about a user configuration file so there should be no need to change the file shipped with the distro.

          • 2. Re: [JBPM 4] Process variable
            Adolf Grazou Newbie

            The problem is that JBPM does not recognize your Object as a persistable object.

            JBPM is capable of persisting Beans by itself, as long as the primary key is a Long or a String, as well as Standard Java Objects.

            If the Object you are trying to persist does not enter in that category, you will have to :
            * modify jbpm.variable.types.xml to make JBPM know this Class
            * Possibly to write a new class implementing org.jbpm.pvm.internal.type.variable (then refer to it in jbpm.variable.types.xml )
            * Possibly to write a Converter also.

            My choice would be to handle all the persistance in the Variable Class.

            Hope this helps.

            • 3. Re: [JBPM 4] Process variable
              Pawel Janusz Newbie

              Thanks for Your info. I found that there is a problem with persistence of variables in JBPM 4.0 which has been solved in 4.1. I've changed jBPM version and my code works correctly.

              • 4. Re: [JBPM 4] Process variable
                Dan Mihai Ile Newbie

                Hello.

                my problem I think is related as the suggestion here, I am unable to create a custom variable:

                I edited the jbpm.variable.types.xml and added my class (basically just pointed the serializable line to my class which is a exact copy of the BlobVariable)

                 

                But even so it says:

                 

                org.hibernate.HibernateException: instance not of expected entity type: org.jbpm.pvm.internal.type.variable.Blob64Variable is not a: org.jbpm.pvm.internal.type.Variable
                    at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassEntityPersister(AbstractEntityPersister.java:3663)
                    at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1374)
                    at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:203)
                    at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:535)
                    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:103)
                    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
                    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:534)
                    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:526)
                    at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:241)
                    at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:291)
                    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:239)
                    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:192)
                    at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:319)
                    at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:265)
                    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:242)
                    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:192)
                    at org.hibernate.engine.Cascade.cascade(Cascade.java:153)
                    at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:154)
                    at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:145)
                    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88)
                    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
                    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
                    at org.jbpm.pvm.internal.tx.HibernateSessionResource.prepare(HibernateSessionResource.java:56)
                    at org.jbpm.pvm.internal.tx.StandardTransaction.commit(StandardTransaction.java:107)
                    at org.jbpm.pvm.internal.tx.StandardTransaction.complete(StandardTransaction.java:64)
                    at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:61)
                    at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
                    at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
                    at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
                    at org.jbpm.pvm.internal.svc.SkipInterceptor.execute(SkipInterceptor.java:43)
                    at org.jbpm.pvm.internal.svc.ExecutionServiceImpl.setVariable(ExecutionServiceImpl.java:145)
                    at expediente_generico.test.TestExpedienteAssincrono3.testNoSubProcess(TestExpedienteAssincrono3.java:41)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at junit.framework.TestCase.runTest(TestCase.java:164)
                    at org.jbpm.test.BaseJbpmTestCase.runTest(BaseJbpmTestCase.java:80)
                    at junit.framework.TestCase.runBare(TestCase.java:130)
                    at junit.framework.TestResult$1.protect(TestResult.java:106)
                    at junit.framework.TestResult.runProtected(TestResult.java:124)
                    at junit.framework.TestResult.run(TestResult.java:109)
                    at junit.framework.TestCase.run(TestCase.java:120)
                    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
                    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
                    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
                    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
                    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
                    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

                 

                Iam using v4.3, If I made exact copy of the BlobVariable, how come it does not work?

                (I also teste extending BlobVariable instead of directly Variable, but still no success)

                • 5. Re: [JBPM 4] Process variable
                  HuiSheng Xu Master

                  Hi Dan,

                   

                  If you want to add a new persistence class to hibernate.  you have to add some information into the jbpm.execution.hbm.xml.  Like this:

                   

                  <subclass name="org.jbpm.pvm.internal.type.variable.BlobVariable" extends="org.jbpm.pvm.internal.type.Variable" discriminator-value="blob">
                      <many-to-one name="lob"
                                   column="LOB_" 
                                   cascade="all"
                                  
                                   foreign-key="FK_VAR_LOB"
                                   index="IDX_VAR_LOB" />
                    </subclass>
                  

                   

                  Then hibernate could know how to deal with your custom class type.

                   

                  Then jbpm.variable.types.xml is used to convert different variable value to the related class type. and the jbpm.execution.hbm.xml is used to tell hibernate how to store these instances.