9 Replies Latest reply on Jan 4, 2006 2:29 PM by Alejandro Guizar

    HibernateException when calling ProcessInstance.getTaskMgmtI

    Nadeem Awad Newbie

      Dear All,
      I'm trying to create a small workflow example using the jBPM.
      I created the ProcessDefinition, and the ProcessInstance, stored them in the hypersonic database:

      factory = JbpmSessionFactory.buildJbpmSessionFactory();
      factory.getJbpmSchema().createSchema();
      JbpmSession session = factory.openJbpmSession();
      session.getGraphSession().saveProcessDefinition(processDefinition);
      session.getGraphSession().saveProcessInstance(processInstance);
      session.close();
      

      Now, the first node in my Process is a task node. So, when I call signal() on the processInstance, the AssignmentHandler is called and executed normally. The problem is when I try to load the ProcessInstance from the database, and call the getTaskMgmtInstance() method:
      JbpmSession session = factory.openJbpmSession();
      ProcessInstance processInstance = session.getGraphSession().loadProcessInstance(1);
      TaskMgmtInstance taskMgmt = processInstance.getTaskMgmtInstance();

      I get the following exception:
      org.hibernate.HibernateException: null index column for collection: org.jbpm.graph.exe.ProcessInstance.instances
       at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:618)
       at org.hibernate.collection.PersistentMap.readFrom(PersistentMap.java:197)
       at org.hibernate.loader.Loader.readCollectionElement(Loader.java:674)
       at org.hibernate.loader.Loader.readCollectionElements(Loader.java:370)
       at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:314)
       at org.hibernate.loader.Loader.doQuery(Loader.java:412)
       at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
       at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)
       at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
       at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
       at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
       at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)
       at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:176)
       at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
       at org.hibernate.collection.PersistentMap.get(PersistentMap.java:123)
       at org.jbpm.graph.exe.ProcessInstance.getInstance(ProcessInstance.java:136)
       at org.jbpm.graph.exe.ProcessInstance.getTaskMgmtInstance(ProcessInstance.java:170)
       at org.jbpm.nadeem.NadeemTaskAssignment.processTaskById(NadeemTaskAssignment.java:247)
      
      

      NadeemTaskAssignment is my test class.

      The thing is, when I try to do this without persistence, it works fine, I call the getTaskMgmtInstance() method and retrieve the list of tasks. I encounter this problem only when I store and load the ProcessInstance in the database.

      Thank you.

        • 1. Re: HibernateException when calling ProcessInstance.getTaskM
          Pablo Lalloni Newbie

          I wonder if you solved this issue and how you did it since we're having the very same problem right now and we're completely lost...

          Have you?

          • 2. Re: HibernateException when calling ProcessInstance.getTaskM
            Nadeem Awad Newbie

            Unfortunately I haven't, because we've abandoned the whole jBPM and Implemented our own workflow solution. Because it seems that the jBPM is still immature and bug infested.

            Good luck

            • 3. Re: HibernateException when calling ProcessInstance.getTaskM
              Pablo Lalloni Newbie

              Well... we really don't want to switch BPM engines ATM so here is my stack trace. As can be seen, the error occurs when I try to ask a ContextInstance from my just loaded ProcessInstance, obviously the problem refers to hibernate lazy loading but since I'm not familiar with JBPM hbm mappings I really can't figure it out.

              org.hibernate.HibernateException: null index column for collection: org.jbpm.graph.exe.ProcessInstance.instances
               at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:618)
               at org.hibernate.collection.PersistentMap.readFrom(PersistentMap.java:197)
               at org.hibernate.loader.Loader.readCollectionElement(Loader.java:674)
               at org.hibernate.loader.Loader.readCollectionElements(Loader.java:370)
               at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:314)
               at org.hibernate.loader.Loader.doQuery(Loader.java:412)
               at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
               at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)
               at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
               at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
               at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
               at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)
               at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:176)
               at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
               at org.hibernate.collection.PersistentMap.get(PersistentMap.java:123)
               at org.jbpm.graph.exe.ProcessInstance.getInstance(ProcessInstance.java:136)
               at org.jbpm.graph.exe.ProcessInstance.getContextInstance(ProcessInstance.java:163)
               at yetem.teg.server.BrokerImplementation.execute(BrokerImplementation.java:121)
               at yetem.teg.server.BrokerImplementation.execute(BrokerImplementation.java:114)
               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 aeglos.interceptors.MethodInterceptorFactory$MethodInvocationImpl.proceed(MethodInterceptorFactory.java:157)
               at yetem.teg.security.TokenVerifierMethodInterceptor.invoke(TokenVerifierMethodInterceptor.java:43)
               at $MethodInterceptor_1088db08cac.invoke($MethodInterceptor_1088db08cac.java)
               at aeglos.interceptors.MethodInterceptorFactory$MethodInterceptorInvocationHandler.invoke(MethodInterceptorFactory.java:110)
               at $Proxy0.execute(Unknown Source)
               at $Broker_1088db08caf.execute($Broker_1088db08caf.java)
               at $Broker_1088db08c96.execute($Broker_1088db08c96.java)
               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 com.caucho.hessian.server.HessianSkeleton.invoke(HessianSkeleton.java:157)
               at net.sourceforge.hiveremoting.caucho.HessianRemoteServiceInvoker.invoke(HessianRemoteServiceInvoker.java:52)
               at net.sourceforge.hiveremoting.caucho.AbstractRemoteServiceInvoker.invoke(AbstractRemoteServiceInvoker.java:78)
               at net.sourceforge.hiveremoting.caucho.CauchoRemotingServlet.service(CauchoRemotingServlet.java:181)
               at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
               at org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:832)
               at net.sourceforge.hiveutils.web.HiveMindRegistryPublishFilter.doFilter(HiveMindRegistryPublishFilter.java:76)
               at org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:823)
               at org.apache.hivemind.servlet.HiveMindFilter.doFilter(HiveMindFilter.java:172)
               at org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:823)
               at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:473)
               at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:556)
               at org.mortbay.http.HttpContext.handle(HttpContext.java:1563)
               at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:623)
               at org.mortbay.http.HttpContext.handle(HttpContext.java:1515)
               at org.mortbay.http.HttpServer.service(HttpServer.java:956)
               at org.mortbay.http.HttpConnection.service(HttpConnection.java:814)
               at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:981)
               at org.mortbay.http.HttpConnection.handle(HttpConnection.java:831)
               at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
               at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
               at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
              


              Just in case is relevant, I'm using MySQL and this is my hibernate.cfg.xml:

              <hibernate-configuration>
               <session-factory>
              
               <!-- jdbc connection properties -->
               <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
               <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
               <property name="hibernate.connection.url">jdbc:mysql://localhost/teg</property>
               <property name="hibernate.connection.username">teg</property>
               <property name="hibernate.connection.password">teg</property>
              
               <!-- c3p0 connection pooling properties
               <property name="hibernate.c3p0.min_size">1</property>
               <property name="hibernate.c3p0.max_size">3</property>
               -->
              
               <!-- other hibernate properties -->
               <property name="hibernate.show_sql">false</property>
              
               <!--identity mapping files -->
               <!-- uncomment if you don't want to use the default jBPM identity mgmgt component
               <mapping resource="org/jbpm/identity/User.hbm.xml"/>
               <mapping resource="org/jbpm/identity/Group.hbm.xml"/>
               <mapping resource="org/jbpm/identity/Membership.hbm.xml"/>
               -->
              
               <!-- graph.def mapping files -->
               <mapping resource="org/jbpm/graph/def/ProcessDefinition.hbm.xml"/>
               <mapping resource="org/jbpm/graph/def/Node.hbm.xml"/>
               <mapping resource="org/jbpm/graph/def/Transition.hbm.xml"/>
               <mapping resource="org/jbpm/graph/def/Event.hbm.xml"/>
               <mapping resource="org/jbpm/graph/def/Action.hbm.xml"/>
               <mapping resource="org/jbpm/graph/def/SuperState.hbm.xml"/>
               <mapping resource="org/jbpm/graph/def/ExceptionHandler.hbm.xml"/>
               <mapping resource="org/jbpm/instantiation/Delegation.hbm.xml"/>
              
               <!-- graph.node mapping files -->
               <mapping resource="org/jbpm/graph/node/StartState.hbm.xml"/>
               <mapping resource="org/jbpm/graph/node/EndState.hbm.xml"/>
               <mapping resource="org/jbpm/graph/node/ProcessState.hbm.xml"/>
               <mapping resource="org/jbpm/graph/node/Decision.hbm.xml"/>
               <mapping resource="org/jbpm/graph/node/Fork.hbm.xml"/>
               <mapping resource="org/jbpm/graph/node/Join.hbm.xml"/>
               <mapping resource="org/jbpm/graph/node/State.hbm.xml"/>
               <mapping resource="org/jbpm/graph/node/TaskNode.hbm.xml"/>
              
               <!-- graph.action mapping files -->
               <mapping resource="org/jbpm/graph/action/Script.hbm.xml"/>
              
               <!-- context.def mapping files -->
               <mapping resource="org/jbpm/context/def/ContextDefinition.hbm.xml"/>
               <mapping resource="org/jbpm/context/def/VariableAccess.hbm.xml"/>
              
               <!-- taskmgmt.def mapping files -->
               <mapping resource="org/jbpm/taskmgmt/def/TaskMgmtDefinition.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/def/Swimlane.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/def/Task.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/def/TaskController.hbm.xml"/>
              
               <!-- module.def mapping files -->
               <mapping resource="org/jbpm/module/def/ModuleDefinition.hbm.xml"/>
              
               <!-- bytes mapping files -->
               <mapping resource="org/jbpm/bytes/ByteArray.hbm.xml"/>
              
               <!-- file.def mapping files -->
               <mapping resource="org/jbpm/file/def/FileDefinition.hbm.xml"/>
              
               <!-- scheduler.def mapping files -->
               <mapping resource="org/jbpm/scheduler/def/CreateTimerAction.hbm.xml"/>
               <mapping resource="org/jbpm/scheduler/def/CancelTimerAction.hbm.xml"/>
              
               <!-- graph.exe mapping files -->
               <mapping resource="org/jbpm/graph/exe/Comment.hbm.xml"/>
               <mapping resource="org/jbpm/graph/exe/ProcessInstance.hbm.xml"/>
               <mapping resource="org/jbpm/graph/exe/Token.hbm.xml"/>
               <mapping resource="org/jbpm/graph/exe/RuntimeAction.hbm.xml"/>
              
               <!-- module.exe mapping files -->
               <mapping resource="org/jbpm/module/exe/ModuleInstance.hbm.xml"/>
              
               <!-- context.exe mapping files -->
               <mapping resource="org/jbpm/context/exe/ContextInstance.hbm.xml"/>
               <mapping resource="org/jbpm/context/exe/TokenVariableMap.hbm.xml"/>
               <mapping resource="org/jbpm/context/exe/VariableInstance.hbm.xml"/>
               <mapping resource="org/jbpm/context/exe/variableinstance/ByteArrayInstance.hbm.xml"/>
               <mapping resource="org/jbpm/context/exe/variableinstance/DateInstance.hbm.xml"/>
               <mapping resource="org/jbpm/context/exe/variableinstance/DoubleInstance.hbm.xml"/>
               <mapping resource="org/jbpm/context/exe/variableinstance/HibernateLongInstance.hbm.xml"/>
               <mapping resource="org/jbpm/context/exe/variableinstance/HibernateStringInstance.hbm.xml"/>
               <mapping resource="org/jbpm/context/exe/variableinstance/LongInstance.hbm.xml"/>
               <mapping resource="org/jbpm/context/exe/variableinstance/StringInstance.hbm.xml"/>
              
               <!-- taskmgmt.exe mapping files -->
               <mapping resource="org/jbpm/taskmgmt/exe/TaskMgmtInstance.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/exe/TaskInstance.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/exe/PooledActor.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/exe/SwimlaneInstance.hbm.xml"/>
              
               <!-- scheduler.exe mapping files -->
               <mapping resource="org/jbpm/scheduler/exe/Timer.hbm.xml"/>
              
               <!-- logging mapping files -->
               <mapping resource="org/jbpm/logging/log/ProcessLog.hbm.xml"/>
               <mapping resource="org/jbpm/logging/log/MessageLog.hbm.xml"/>
               <mapping resource="org/jbpm/logging/log/CompositeLog.hbm.xml"/>
               <mapping resource="org/jbpm/graph/log/ActionLog.hbm.xml"/>
               <mapping resource="org/jbpm/graph/log/NodeLog.hbm.xml"/>
               <mapping resource="org/jbpm/graph/log/ProcessInstanceCreateLog.hbm.xml"/>
               <mapping resource="org/jbpm/graph/log/ProcessInstanceEndLog.hbm.xml"/>
               <mapping resource="org/jbpm/graph/log/SignalLog.hbm.xml"/>
               <mapping resource="org/jbpm/graph/log/TokenCreateLog.hbm.xml"/>
               <mapping resource="org/jbpm/graph/log/TokenEndLog.hbm.xml"/>
               <mapping resource="org/jbpm/graph/log/TransitionLog.hbm.xml"/>
               <mapping resource="org/jbpm/context/log/VariableLog.hbm.xml"/>
               <mapping resource="org/jbpm/context/log/VariableCreateLog.hbm.xml"/>
               <mapping resource="org/jbpm/context/log/VariableDeleteLog.hbm.xml"/>
               <mapping resource="org/jbpm/context/log/VariableUpdateLog.hbm.xml"/>
               <mapping resource="org/jbpm/context/log/variableinstance/ByteArrayUpdateLog.hbm.xml"/>
               <mapping resource="org/jbpm/context/log/variableinstance/DateUpdateLog.hbm.xml"/>
               <mapping resource="org/jbpm/context/log/variableinstance/DoubleUpdateLog.hbm.xml"/>
               <mapping resource="org/jbpm/context/log/variableinstance/HibernateLongUpdateLog.hbm.xml"/>
               <mapping resource="org/jbpm/context/log/variableinstance/HibernateStringUpdateLog.hbm.xml"/>
               <mapping resource="org/jbpm/context/log/variableinstance/LongUpdateLog.hbm.xml"/>
               <mapping resource="org/jbpm/context/log/variableinstance/StringUpdateLog.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/log/TaskLog.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/log/TaskCreateLog.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/log/TaskAssignLog.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/log/TaskEndLog.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/log/SwimlaneLog.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/log/SwimlaneCreateLog.hbm.xml"/>
               <mapping resource="org/jbpm/taskmgmt/log/SwimlaneAssignLog.hbm.xml"/>
              
               </session-factory>
              </hibernate-configuration>
              


              Here's the code snippet that reproduces the exception:

              ProcessInstance instance = jbpmSession.getGraphSession().loadProcessInstance(game.getProcessId());
              
              instance.getContextInstance().setTransientVariable(Constants.GAME_VAR, game);
              
              instance.getContextInstance().setTransientVariable(Constants.REGISTRY_VAR, HiveMindRegistryPublishFilter.getRegistry());
              
              instance.getContextInstance().addVariables(arguments);
              
              instance.signal(commandName);
              
              jbpmSession.getGraphSession().saveProcessInstance(instance);
              


              Above, in the first line reading instance.getContextInstance()... the exception is thrown.

              Can somebody help us?

              • 4. Re: HibernateException when calling ProcessInstance.getTaskM
                Fred Muhlenberg Newbie

                I ran into a similar problem when using the Hypersonic database within jBoss and my temporary solution when saving a ProcessDefinition was to catch the exception that is generated during the commit.

                As in:

                jbpmSession.beginTransaction
                jbpmSession.getGraphSession().saveProcessDefinition( pd )
                try
                {
                jbpmSession.commitTransaction();
                }
                catch( Exception e )
                {
                // Ignore
                }
                finally
                {
                jbpmSession.close();
                }

                I found that things gets persisted correctly even though the exception is generated. I don't like ignoring the exception but I don't know enough about Hibernate and its configurations and I don't have a sufficient development environment to investigate further.

                • 5. Re: HibernateException when calling ProcessInstance.getTaskM
                  Alejandro Guizar Master

                  I'm investigating the problem. In the meantime please tell me the version you are using.

                  • 6. Re: HibernateException when calling ProcessInstance.getTaskM
                    Alejandro Guizar Master

                    Another question: does your code snippet work with Hypersonic?

                    • 7. Re: HibernateException when calling ProcessInstance.getTaskM
                      Pablo Lalloni Newbie

                       

                      "alex.guizar@jboss.com" wrote:
                      I'm investigating the problem. In the meantime please tell me the version you are using.


                      JBPM 3.0.2

                      "alex.guizar@jboss.com" wrote:
                      Another question: does your code snippet work with Hypersonic?


                      With Hypersonic the same problem is reproduced

                      • 8. Re: HibernateException when calling ProcessInstance.getTaskM
                        Pablo Lalloni Newbie

                        Ok, we solved it!

                        The problem dissappeared by doing 2 changes to our code:

                        1. Persisting the process definition before saving the process instance

                        2. Putting calls to beginTransaction() and commitTransaction() around the saving of the process instance (and around the saving of the process definition)

                        We didn't do 1 before because we'll have just one process definition, no more than one version of it, and we didn't see the part of docs where it says that we must persist process definition before its instances.

                        We didn't do 2 because we were planning to put some transaction interceptor around those methods (which weren't in place yet).

                        So, is this the expected way of this stuff to work?

                        • 9. Re: HibernateException when calling ProcessInstance.getTaskM
                          Alejandro Guizar Master

                           

                          "plalloni" wrote:
                          Ok, we solved it!

                          Glad to hear it!
                          "plalloni" wrote:
                          we didn't see the part of docs where it says that we must persist process definition before its instances.

                          This is a subtle one. The database example in Chapter 3 of the jBPM user guide starts with saving the definition...
                          "plalloni" wrote:
                          we were planning to put some transaction interceptor around those methods (which weren't in place yet)

                          Hibernate (and hence jBPM) can be made aware of managed transactions, in which case the calls to beginTransaction() or commitTransaction() need not be present. You must explicitly demarcate transactions in an unmanaged environment. If you want to move freely between both environments, just leave the demarcations. Hibernate will ignore them in the managed case.