7 Replies Latest reply on Jan 8, 2009 1:39 PM by Jason Farmer

    Trying to persist process instances - need some help

    Jason Farmer Newbie

      Hi All,

      I'm new to jBpm here and have been trying to follow some of the guides on the JBoss site as well as some examples included in the Jbpm distribution. I've successfully created some simple examples and am now trying to work with some DB persistence.

      I am using Jboss 5, JBpm 3.3. The Mysql database has been created using the DB scripts included in the starter kit.

      I have a simple process definition defined as follows:

      <process-definition xmlns="urn:jbpm.org:jpdl-3.2" name="TestProcess">
      
      
       <start-state name="start">
       <transition to="auction" name="to-auction"></transition>
       </start-state>
      
       <decision name="meets-minimum">
       <handler class="com.test.decision.AcceptBid"></handler>
       <transition to="end" name="yes"></transition>
       <transition to="auction" name="no"></transition>
       </decision>
      
       <state name="auction">
       <transition to="enter-bid" name="to-bid"></transition>
       </state>
      
       <task-node name="enter-bid">
       <task name="make-bid">
       <controller></controller>
       </task>
       <transition to="meets-minimum" name="to-meets-minimum"></transition>
       </task-node>
      
      
       <end-state name="end"></end-state>
      
      
      </process-definition>
      


      I am trying to use the process by doing:
       JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseResource("jbpm.cfg.xml");
       JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
      
       try{
       log.debug("Test main - Creating process definition.");
       ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource("TestProcess/processdefinition.xml");
       log.debug("Test main - deploying process definition");
       jbpmContext.deployProcessDefinition(processDefinition);
       log.debug("Test main - Creating process instance");
       ProcessInstance processInstance = jbpmContext.newProcessInstance("TestProcess");
       log.debug("Test main - signaling process instance");
       log.debug("Test main - Process instance in state: "+ processInstance.getRootToken().getNode().getName());
       processInstance.signal();
       }
       finally
       {
       jbpmContext.close();
       }
      


      The jbpm.cfg.xml is simple (following one of the examples)
      <jbpm-configuration>
      <jbpm-context>
       <service name='persistence' factory='org.jbpm.persistence.db.DbPersistenceServiceFactory' />
      </jbpm-context>
      </jbpm-configuration>
      


      When I try to execute the code above, I get the following exception with this root cause:

      org.hibernate.PropertyAccessException: could not get a field value by reflection getter of org.jbpm.graph.def.Node.id
       org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:58)
       org.hibernate.engine.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:67)
       org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:67)
      
      Root Cause
      
      java.lang.IllegalArgumentException: Can not set long field org.jbpm.graph.def.GraphElement.id to org.jbpm.graph.node.MailNode
       sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
       sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
       sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
       sun.reflect.UnsafeLongFieldAccessorImpl.getLong(UnsafeLongFieldAccessorImpl.java:42)
       sun.reflect.UnsafeLongFieldAccessorImpl.get(UnsafeLongFieldAccessorImpl.java:18)
       java.lang.reflect.Field.get(Field.java:358)
      



      I get the same problem when I use the Hsql database as well.

      What's puzzling me is that when I do not initialize my own context, the process seems to run fine (although my processes do not persist in my database).

      Can anyone help shed light on this for me? Thanks for any help!

        • 1. Re: Trying to persist process instances - need some help
          Ronald van Kuijk Master

          you forgot to save the processinstance.... closing the context is not enough

          • 2. Re: Trying to persist process instances - need some help
            Jason Farmer Newbie

            Good point! Thanks for that. I must have removed it while trying different things. Unfortunately I still receive the same exception.

            Not saving it should only prevent me from trying to retrieve it later, which I haven't even gotten to that point, right? I begin getting this exception as soon as I set up my jbpmContext manually.

            Any other thoughts?

            • 3. Re: Trying to persist process instances - need some help
              Ronald van Kuijk Master

              You should either use a more complete full jbpm.cfg.xml or leave it out so the default will be used. Not sure if that is the cause.

              • 4. Re: Trying to persist process instances - need some help
                Jason Farmer Newbie

                Thanks again for the help kukeltje,

                If I remove the jbpm.cfg.xml I'm not exactly sure how to get a hold of my jbpmContext, I tried:

                 JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
                 JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
                


                But that leaves me with this exception
                java.lang.ClassCastException: org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory cannot be cast to org.jbpm.svc.ServiceFactory
                 org.jbpm.svc.Services.getServiceFactory(Services.java:117)
                 org.jbpm.svc.Services.getService(Services.java:134)
                


                I tried putting my jbpm.cfg.xml back and added a bit more content, following the included guide for jBPM and made my jbpm.cfg.xml look as follows:

                <jbpm-configuration>
                
                 <jbpm-context>
                 <service name='persistence' factory='org.jbpm.persistence.db.DbPersistenceServiceFactory' />
                 </jbpm-context>
                
                 <string name='resource.hibernate.cfg.xml' value='hibernate.cfg.xml' />
                 <string name='resource.business.calendar' value='org/jbpm/calendar/jbpm.business.calendar.properties' />
                 <string name='resource.default.modules' value='org/jbpm/graph/def/jbpm.default.modules.properties' />
                 <string name='resource.converter' value='org/jbpm/db/hibernate/jbpm.converter.properties' />
                 <string name='resource.action.types' value='org/jbpm/graph/action/action.types.xml' />
                 <string name='resource.node.types' value='org/jbpm/graph/node/node.types.xml' />
                 <string name='resource.varmapping' value='org/jbpm/context/exe/jbpm.varmapping.xml' />
                </jbpm-configuration>
                


                I get the same error:
                java.lang.IllegalArgumentException: Can not set long field org.jbpm.graph.def.GraphElement.id to org.jbpm.graph.node.MailNode
                 sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
                 sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.jav
                


                I'm confused as to why it's trying to create a "MailNode" anyway. None of my nodes in my process definition are MailNodes. Does having a task-node force it to also create a MailNode? I could try an even simpler example with only a single StateNode to see if it works at all with explicitly saving.

                Any thoughts? I really appreciate the help!

                • 5. Re: Trying to persist process instances - need some help
                  Ronald van Kuijk Master

                  The classcast exception is already weird... Can you make a eclipse or maven project with minimal code in it that demonstrates the problem? I can try to reproduce here then

                  • 6. Re: Trying to persist process instances - need some help
                    Jason Farmer Newbie

                    So it turns out I think I had a couple of things missing/wrong. (Of course :) )

                    So #1, it seems when trying to load up an external DB and use the jbpm-console there are a couple of things that should be known:

                    a) The database build scripts located under {jbpm-install}/database do not include any of the authentication tables needed to actually use the jbpm-console web app.
                    b) When installing jbpm through the jar installer, if you chose hypersonic as your database, it *will* however give you the correct tables needed for jbpm-console (hence why it works out of the box)

                    So what I ended up doing was copying the SQL out of my {jboss-server}/data/hypersonic/JbpmDB.script that hypersonic was using to create the remaining tables needed for my jbpm-console to work correctly.

                    Once I was able to get the console working correctly (knowing I had the correct DB settings and hibernate) I was able to then compare/use these settings in my own app.

                    I'm working closer to getting it working correctly. Now I'm getting what seems to be a more manageable exception :)

                    org.hibernate.AssertionFailure: null id in org.jbpm.graph.def.ProcessDefinition entry (don't flush the Session after an exception occurs)

                    I'm happy though that the jbpm-console examples are working and persisting correctly to Mysql!

                    • 7. Re: Trying to persist process instances - need some help
                      Jason Farmer Newbie

                      Specifically the tables were JBPM_ID_GROUP, JBPM_ID_USER, JBPM_ID_MEMBERSHIP, and JBPM_ID_PERMISSIONS.

                      Also #2 I had wrong, I think there were some errors in my hibernate config. I came across another example located here:

                      http://jboss.org/community/docs/DOC-11139

                      And was able to use some of their configurations to get over that hump. So now I'm pretty sure the remaining problems are specific to my code (instead of the Jbpm setup files)