Moodle Social Bookmarking Activity Applying for a Google SoC at few hours to deadline
Apr 04

After deploying a new process I sure that you would like to run it ;)

It’s easy. First of all, you must create a new process instance:

        jbpmContext = jbpmConfiguration.createJbpmContext();
        processInstance = jbpmContext.newProcessInstance("processname");

Then you can initialize it by adding some variables to the process:

        contextInstance = processInstance.getContextInstance();
	contextInstance.setVariable("var", myVar);

To start it you have to send a signal to the process first token :

	processInstance.getRootToken().signal();

Related Posts

8 Responses to “Run a jBPM process”

  1. aPoLiOn Says:

    Why are you learning jBPM? Are you involved in some university project or it’s just for fun?

    And a final question: is P for Process or for Performance?

  2. pigui Says:

    It sounds like a SIO question… ;)

  3. Christian Says:

    Useful post, I spent many days trying to find it out, but at last I get it (looking some examples and of course reading the -boring- JBpm doc).

    Now I am trying to start a process instance with Web Services from a remote client (a nagios server that could start a work-flow when an alarm is detected), but I realized that it is kind of complicated, because the few examples that I found on the Internet are oriented to start a process instance from a node of the JBpm and not from a remote client.

    I will really apreciatte if maybe you know how to solve this problem or maybe you could give me some tips to accomplish this task.

    Thanks

    Christian

  4. Christian Says:

    One last question:

    How can you initialize the object “jbpmConfiguration” if you don’t have an ExecutionContext:

    JbpmConfiguration jbpmConfiguration=???
    jbpmContext = jbpmConfiguration.createJbpmContext();

  5. pigui Says:

    Hi Christian,

    I never tried to start a process using WS but I suppose it doesn’t matter. Once at server start it normally.

    To init the JbpmConfiguration you need to read the xml config file. jBPM API encapsulates this operation at parseResourse function. You only need to do the following :

    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseResource(”/config/jbpm.cfg.xml”); // or wherever is your jbpm.cfg.xml file

    I hope it helps you.

  6. Christian Says:

    Thanks pigui, I’ll take in count your suggestions.

  7. btl_ayd Says:

    Hi.
    I tred to start process using java class.But coudnt.here is my code and error has been occured:
    public class uzak {

    /**
    * @param args
    */
    JbpmConfiguration jbpmConfiguration = null;
    //JbpmConfiguration.getInstance();

    public static void startProcessDefinition() {
    String processDefinitionName = new String(”websale”);
    JbpmConfiguration jbpmConfiguration =JbpmConfiguration.parseResource(”jbpm.cfg.xml”);
    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
    try {
    GraphSession graphSession = jbpmContext.getGraphSession();
    ProcessDefinition definition = graphSession.findLatestProcessDefinition(processDefinitionName);
    System.out.println(graphSession.getProcessDefinition(2));
    ProcessInstance instance = definition.createProcessInstance();
    instance.signal();

    jbpmContext.save(instance);
    } finally {
    jbpmContext.close();
    }
    }
    public static void main(String[] args) {

    uzak.startProcessDefinition();
    }

    }
    here is error
    Table not found in statement [select top ? processdef0_.ID_ as ID1_0_, processdef0_.NAME_ as NAME3_0_, processdef0_.DESCRIPTION_ as DESCRIPT4_0_, processdef0_.VERSION_ as VERSION5_0_, processdef0_.ISTERMINATIONIMPLICIT_ as ISTERMIN6_0_, processdef0_.STARTSTATE_ as STARTSTATE7_0_ from JBPM_PROCESSDEFINITION processdef0_ where processdef0_.NAME_=? order by processdef0_.VERSION_ desc]
    org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.loader.Loader.doList(Loader.java:2223)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    at org.hibernate.loader.Loader.list(Loader.java:2099)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:811)
    at org.jbpm.db.GraphSession.findLatestProcessDefinition(GraphSession.java:153)
    at uzak.startProcessDefinition(uzak.java:43)
    at uzak.main(uzak.java:55)
    Caused by: java.sql.SQLException: Table not found in statement [select top ? processdef0_.ID_ as ID1_0_, processdef0_.NAME_ as NAME3_0_, processdef0_.DESCRIPTION_ as DESCRIPT4_0_, processdef0_.VERSION_ as VERSION5_0_, processdef0_.ISTERMINATIONIMPLICIT_ as ISTERMIN6_0_, processdef0_.STARTSTATE_ as STARTSTATE7_0_ from JBPM_PROCESSDEFINITION processdef0_ where processdef0_.NAME_=? order by processdef0_.VERSION_ desc]
    at org.hsqldb.jdbc.Util.throwError(Unknown Source)
    at org.hsqldb.jdbc.jdbcPreparedStatement.(Unknown Source)
    at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
    at org.hibernate.loader.Loader.doQuery(Loader.java:673)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    at org.hibernate.loader.Loader.doList(Loader.java:2220)
    … 11 more
    11:45:00,774 [main] ERROR GraphSession : org.hibernate.exception.SQLGrammarException: could not execute query
    11:45:00,774 [main] DEBUG JbpmContext : closing JbpmContext
    11:45:00,774 [main] DEBUG Services : closing service ‘persistence’: org.jbpm.persistence.db.DbPersistenceService@11a0d35
    Exception in thread “main” org.jbpm.JbpmException: couldn’t find process definition ‘websale’
    at org.jbpm.db.GraphSession.findLatestProcessDefinition(GraphSession.java:170)
    at uzak.startProcessDefinition(uzak.java:43)
    at uzak.main(uzak.java:55)
    Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.loader.Loader.doList(Loader.java:2223)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    at org.hibernate.loader.Loader.list(Loader.java:2099)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:811)
    at org.jbpm.db.GraphSession.findLatestProcessDefinition(GraphSession.java:153)
    … 2 more
    Caused by: java.sql.SQLException: Table not found in statement [select top ? processdef0_.ID_ as ID1_0_, processdef0_.NAME_ as NAME3_0_, processdef0_.DESCRIPTION_ as DESCRIPT4_0_, processdef0_.VERSION_ as VERSION5_0_, processdef0_.ISTERMINATIONIMPLICIT_ as ISTERMIN6_0_, processdef0_.STARTSTATE_ as STARTSTATE7_0_ from JBPM_PROCESSDEFINITION processdef0_ where processdef0_.NAME_=? order by processdef0_.VERSION_ desc]
    at org.hsqldb.jdbc.Util.throwError(Unknown Source)
    at org.hsqldb.jdbc.jdbcPreparedStatement.(Unknown Source)
    at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
    at org.hibernate.loader.Loader.doQuery(Loader.java:673)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    at org.hibernate.loader.Loader.doList(Loader.java:2220)
    … 11 more
    11:45:00,774 [main] DEBUG DbPersistenceService : committing hibernate transaction org.hibernate.transaction.JDBCTransaction@3aef16
    11:45:00,774 [main] DEBUG DbPersistenceService : closing hibernate session
    11:45:00,774 [main] DEBUG Services : closing service ‘tx’: org.jbpm.tx.TxService@12c4c57

  8. pigui Says:

    @btl_ayd
    * Did you created jbpm tables into your database?
    http://blogs.dfwikilabs.org/pigui/2007/11/23/installing-jboss-jbpm-332-on-apache-tomcat-55-and-mysql/
    * Did you deployed the process definition?
    http://blogs.dfwikilabs.org/pigui/2008/03/17/deploying-jbpm-processes/

Leave a Reply