Drools – Use Case: Emergency Service – Business Process Implementation (Part 2)

This post will describe the implementation details from the scenario described in the previous post. Based on the sequence of activities that we recognize in the Emergency Service scenario we will model our business process using the BPMN2 specification. Once we get the formal description of our process we will execute it using Drools Flow. This post will describe the main technical points needed to run our business processes.

Please read the disclaimer first

Formalizing our Business Process

Our first step is to define the sequence of activities that we need in order to achieve the business goal. In this case the business goal is to pick up the patient that has suffered an injury and leave him/her in a hospital as quickly as possible. Based on our response time, our service can be qualified using different quality measurements. It’s important for us to be able to measure how each instance of our business process performs in order to discover how we can improve our service. For the managers of our company, it will be important to see in realtime how the processes are being executed. This helps them to make decisions based on the company status; for example, if the number of emergencies per hour is higher than the number of ambulances that the company owns, they will have to buy more ambulances.

Based on the previous process graph, we can model this situation using the BPMN2 notation. I will show here some screenshots of my modeled process into Eclipse using the Drools plugins. You can try also the Oryx Process Modeler to represent your business processes using the BPMN2 notation.

Emergency Service Business Process

Understanding our Business Process Behavior

Before modeling our business processes we need to understand each activity’s behavior to know what will happen in runtime. If we don’t understand when to use each of the activities provided in the palette, we can end up with a process badly described that will not represent correctly our business situation.

Emergency Service BPMN2 Definition

The following list will describe each activity used in this example. If you want a more detailed explanation please refer to the BPMN2 specification:

  • Start Event: indicates that a particular Process will start.
  • User Task: is a typical “workflow” task where a human performer performs the Task with the assistance of a software application, and where the Task is scheduled through a Task list manager of some sort.
  • Parallel Gateway: is used to synchronize (combine) parallel flows and to create parallel flows (split/fork).
  • Intermediate Catch Event: indicates when something happens (an Event) somewhere between the start and end of a Process.
  • Business Rule Task: provide a mechanism for the process to provide input to a Business Rule Engine and get the output of calculations that the Business Rule Engine might provide.
  • Service Task: is a Task that sues some sort of service, which could be a Web Service or an automated application
  • End Event: indicates where a Process will end.

Once we understand these definitions, we will know what will happen when we run our processes.

Drools Flow Implementation and Runtime

I will use the common Drools Flow APIs to implement this scenario. Here I will mention only the important stuff that you need to know plus the information that will travel along our business process. The following code snippet shows the basic stuff needed to load your processes and rules into a compiled knowledge package that will be used by a knowledge base to create new knowledge session.

 KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
 kbuilder.add(new ClassPathResource("EmergencyService.bpmn"), ResourceType.BPMN2);
 kbuilder.add(new ClassPathResource("rules.drl"), ResourceType.DRL);
 if (kbuilder.hasErrors()) {
   for (KnowledgeBuilderError error : kbuilder.getErrors()) {
     System.out.println(error);
   }
   throw new IllegalStateException("Error building kbase!");
 }
 kbase = KnowledgeBaseFactory.newKnowledgeBase();
 kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
 StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);

One important thing to notice here (that was not previously discussed in the previous post) is the use of the persistence features in the example. Most of the time, when we have short (in memory) running processes we don’t need to persist their status into a database. But, for long running processes we need a way to keep the process information out of the main memory. For this reason, we use the JPAKnowledgeService to create a new “Persistable” knowledge session. This Knowledge Session will know how to persist all the necessary information in order to be restored in the future. Because the Process Instances live inside the Knowledge Session they will be persisted automatically when they reach a safe point.

As you can see, the JPAKnowledgeService receives an Environment as a third parameter. This Environment will provide everything needed to persist all the information internally. Take a look at a common configuration for this Environment:

 EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.drools.persistence.jpa");
 env = KnowledgeBaseFactory.newEnvironment();
 env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
 env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());
 env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());

As you can see, the Environment will include an EntityManagerFactory and a TransactionManager. Both will be used to handle all the process information automatically, so you won’t need to worry about it.

As you may already know, the EntityManagerFactory will create a new Persistence Unit (in this case called: org.drools.persistence.jpa) that will be configured to use a JTA DataSource. Take a look at the following XML snippet:

<persistence-unit name="org.drools.persistence.jpa" transaction-type="JTA">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  <jta-data-source>jdbc/testDS1</jta-data-source>
  <class>org.drools.persistence.session.SessionInfo</class>
  <class>org.drools.persistence.processinstance.ProcessInstanceInfo</class>
  <class>org.drools.persistence.processinstance.ProcessInstanceEventInfo</class>
  <class>org.drools.persistence.processinstance.WorkItemInfo</class>
  <class>org.drools.persistence.processinstance.variabletypes.VariableInstanceInfo</class>
  <class>org.drools.persistence.processinstance.variabletypes.JPAPersistedVariable</class>

  <properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
    <property name="hibernate.connection.autocommit" value="false" />
    <property name="hibernate.max_fetch_depth" value="3"/>
    <property name="hibernate.hbm2ddl.auto" value="create" />
    <property name="hibernate.show_sql" value="true" />
    <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup"/>
  </properties>
</persistence-unit>

Note that we use a JTA DataSource to handle all the internal transactions. We choose to use Bitronix as our Transaction Manager, so we need to start a new Pooling DataSource with the following code snippet:

 ds1 = new PoolingDataSource();
 ds1.setUniqueName("jdbc/testDS1");
 ds1.setClassName("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");
 ds1.setMaxPoolSize(5);
 ds1.setAllowLocalTransactions(true);
 ds1.getDriverProperties().put("user","root");
 ds1.getDriverProperties().put("password","");
 ds1.getDriverProperties().put("databaseName", "droolsflow");
 ds1.getDriverProperties().put("serverName", "localhost");

Wrapping up

Right now we are ready to execute our long running processes using the persistence mechanisms provided by Drools Flow. As you may notice there are some extra details needed to interact with our process instances. I will leave these details for a future post about human interactions and domain specific processes.  We need to understand in depth how our users will interact with their User Tasks and how we can notify our process about external events. Also we need to understand how we can model more expressive business processes using the flexibility provided by the specification (Service Tasks) and the flexibility provided by Drools Flow (Work Items).

PS: I’ve included the MySQL 5 configurations, and I also have the H2 and PostgreSQL configurations.  Post me a comment if you need them or if you have tried with another DB vendor. Please share the configurations with the community.

Advertisements

41 thoughts on “Drools – Use Case: Emergency Service – Business Process Implementation (Part 2)”

  1. Hi,
    when i try to run the drools flow process,getting exception..please can you give me some advice…..
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.annotations.Version
    INFO: Hibernate Annotations 3.4.0.GA
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.Environment
    INFO: Hibernate 3.3.0.SP1
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.Environment
    INFO: hibernate.properties not found
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: Bytecode provider name : javassist
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.Environment
    INFO: using JDK 1.4 java.sql.Timestamp handling
    Jun 8, 2010 8:11:13 PM org.hibernate.annotations.common.Version
    INFO: Hibernate Commons Annotations 3.1.0.GA
    Jun 8, 2010 8:11:13 PM org.hibernate.ejb.Version
    INFO: Hibernate EntityManager 3.4.0.GA
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.annotations.QueryBinder bindQuery
    INFO: Binding Named query: ProcessInstancesWaitingForEvent => select processInstanceInfo.processInstanceId from ProcessInstanceInfo processInstanceInfo where :type in elements(processInstanceInfo.eventTypes)
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.session.SessionInfo
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.session.SessionInfo on table SessionInfo
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.ProcessInstanceEventInfo
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.processinstance.ProcessInstanceEventInfo on table ProcessInstanceEventInfo
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.WorkItemInfo
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.processinstance.WorkItemInfo on table WorkItemInfo
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.ProcessInstanceInfo
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.processinstance.ProcessInstanceInfo on table ProcessInstanceInfo
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.AnnotationConfiguration secondPassCompile
    INFO: Hibernate Validator not found: ignoring
    Jun 8, 2010 8:11:13 PM org.hibernate.cfg.search.HibernateSearchEventListenerRegister enableHibernateSearch
    INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
    Jun 8, 2010 8:11:13 PM org.hibernate.util.NamingHelper getInitialContext
    INFO: JNDI InitialContext properties:{}
    Exception in thread “main” javax.persistence.PersistenceException: [PersistenceUnit: org.drools.persistence.jpa] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
    at com.ml.cm.batchclient.WorkFlowPersist.main(WorkFlowPersist.java:49)
    Caused by: org.hibernate.HibernateException: Could not find datasource: jdbc/testDS1
    at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:82)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
    at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
    … 4 more

    Like

  2. yes i added the datasource.
    —————————–One.java———————
    public static PoolingDataSource makeDataSource() {
    PoolingDataSource ds1 = new PoolingDataSource();
    ds1.setUniqueName(“jdbc/SybaseDataSource”);
    ds1.setClassName(“com.sun.sql.jdbcx.sybase.SybaseDataSource”);
    ds1.setMaxPoolSize(5);
    ds1.setAllowLocalTransactions(true);
    ds1.getDriverProperties().put(“user”,”xxxx”);
    ds1.getDriverProperties().put(“password”,”xxxxx”);
    ds1.getDriverProperties().put(“databaseName”, “xxxx”);
    ds1.getDriverProperties().put(“serverName”, “xxxxx”);

    return ds1;
    ——————————————————
    ———————-persistence.xml——————

    org.hibernate.ejb.HibernatePersistence
    jdbc/SybaseDataSource
    org.drools.persistence.session.SessionInfo
    org.drools.persistence.processinstance.ProcessInstanceInfo
    org.drools.persistence.processinstance.ProcessInstanceEventInfo
    org.drools.persistence.processinstance.WorkItemInfo
    org.drools.persistence.processinstance.variabletypes.VariableInstanceInfo
    org.drools.persistence.processinstance.variabletypes.JPAPersistedVariable

    </properties
    ————————————————————
    yes…

    can you please help me out from this issue..?? waiting for your reply thanks.

    Like

  3. Just to be sure, did you start the PoolingDataSource? calling the method ds1.init()??

    Did you see my example about using variable persistence strategies in http://blog.athico.com, I show how to configure all the persistence properties there.
    You need to inform to Hibernate that the transaction manager will be bitronix in the properties and also you need to add a jndi.properties file in the classpath.

    Like

  4. i am using eclipse 3.5..will persistence.xml work without using spring framework.because i have to do drools workflow to be persisted. so that i am using standalone java class, one POJO and persistence.xml.is there anything needed, apart from these?

    Like

  5. Hi, still getting exception…

    code snippet….can you please take a look?

    ………….xxx.java…………..
    Map parameters = new HashMap();
    parameters.put(“x”, “SomeString”);
    parameters.put(“y”, new wrkflow1());
    parameters.put(“z”, new MyVariableSerializable1(“This is a test SerializableObject”));
    KnowledgeBase kbase = readKnowledgeBase();
    VariablePersistenceStrategyFactory.getVariablePersistenceStrategy()
    .setPersister(“javax.persistence.Entity”,
    “org.drools.persistence.processinstance.persisters.JPAVariablePersister”);
    VariablePersistenceStrategyFactory.getVariablePersistenceStrategy()
    .setPersister(“java.io.Serializable”,
    “org.drools.persistence.processinstance.persisters.SerializableVariablePersister”);

    EntityManagerFactory emf = Persistence.createEntityManagerFactory(“org.drools.persistence.jpa”);
    Environment env = KnowledgeBaseFactory.newEnvironment();
    env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
    env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());
    env.set( EnvironmentName.TRANSACTION_MANAGER,TransactionManagerServices.getTransactionManager());
    StatefulKnowledgeSession ksession =JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
    int sessionId = ksession.getId();
    WorkflowProcessInstance processInstance =(WorkflowProcessInstance)ksession.startProcess(“com.ml.cm.batchclient.wrk”, parameters);
    System.out.println(“Session ID:” +sessionId);
    ksession.addEventListener( new DebugWorkingMemoryEventListener() );
    ksession.addEventListener( new DefaultAgendaEventListener() {
    public void afterActivationFired(AfterActivationFiredEvent wrk) {
    super.afterActivationFired( wrk );
    }
    });
    //ProcessInstance processInstance = ksession.startProcess(“com.ml.cm.batchclient.wrk”);
    if(processInstance != null) {
    System.out.println(“Trigering the Event..”);
    processInstance.signalEvent(“REJECT”, wrk);
    }
    /*System.out.println(“Max Pool Size..:” + pds.getMaxPoolSize());
    Properties props=pds.getDriverProperties();
    for ( Enumeration e = props.propertyNames(); e.hasMoreElements(); )
    {
    String key = (String)e.nextElement();
    String value = props.getProperty( key );
    System.out.println( key + “=” + value );
    }*/
    PoolDat1.makeDataSource();
    Context ctx = new InitialContext();
    ctx.createSubcontext(“jdbc”);
    Object ds1 = null;
    ctx.rebind(“jdbc/BitronixJTADataSource”,ds1);
    ctx.close();
    ksession.dispose();
    }

    /*private EntityManager em;
    protected EntityManager getEntityManager() {
    if (em == null)
    throw new IllegalStateException(“EntityManager has not been set”);
    return (EntityManager) em;
    }*/

    private static KnowledgeBase readKnowledgeBase() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(“IQMflow.rf”,WorkflowPerist.class), ResourceType.DRF);
    KnowledgeBuilderErrors errors = kbuilder.getErrors();
    if (errors.size() > 0) {
    for (KnowledgeBuilderError error: errors) {
    System.err.println(error);
    }
    throw new IllegalArgumentException(“Could not parse knowledge.”);
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    return kbase;
    }
    ———————————————————–
    ——————persistence.xml————————–

    org.hibernate.ejb.HibernatePersistence
    jdbc/BitronixJTADataSource
    org.drools.persistence.session.SessionInfo
    org.drools.persistence.processinstance.ProcessInstanceInfo
    org.drools.persistence.processinstance.ProcessInstanceEventInfo
    org.drools.persistence.processinstance.WorkItemInfo
    org.drools.persistence.processinstance.variabletypes.VariableInstanceInfo
    org.drools.persistence.processinstance.variabletypes.JPAPersistedVariable
    org.drools.persistence.processinstance.variabletypes.SerializablePersistedVariable

    ——————————————————
    ———————–jndi.properties…——————
    java.naming.factory.initial=bitronix.tm.jndi.BitronixInitialContextFactory
    ———————————————————–

    Like

  6. Jun 9, 2010 7:36:46 PM org.hibernate.cfg.annotations.Version
    INFO: Hibernate Annotations 3.4.0.GA
    Jun 9, 2010 7:36:46 PM org.hibernate.cfg.Environment
    INFO: Hibernate 3.3.1.GA
    Jun 9, 2010 7:36:46 PM org.hibernate.cfg.Environment
    INFO: hibernate.properties not found
    Jun 9, 2010 7:36:46 PM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: Bytecode provider name : javassist
    Jun 9, 2010 7:36:46 PM org.hibernate.cfg.Environment
    INFO: using JDK 1.4 java.sql.Timestamp handling
    Jun 9, 2010 7:36:46 PM org.hibernate.annotations.common.Version
    INFO: Hibernate Commons Annotations 3.1.0.GA
    Jun 9, 2010 7:36:46 PM org.hibernate.ejb.Version
    INFO: Hibernate EntityManager 3.4.0.GA
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: com.ml.cm.batchclient.wrkflow1 -> WRKFLOW
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.session.SessionInfo
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.session.SessionInfo on table SessionInfo
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.ProcessInstanceInfo
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.processinstance.ProcessInstanceInfo on table ProcessInstanceInfo
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.ProcessInstanceEventInfo
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.processinstance.ProcessInstanceEventInfo on table ProcessInstanceEventInfo
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.WorkItemInfo
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.processinstance.WorkItemInfo on table WorkItemInfo
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.variabletypes.VariableInstanceInfo
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.processinstance.variabletypes.VariableInstanceInfo on table VariableInstanceInfo
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.variabletypes.JPAPersistedVariable
    Jun 9, 2010 7:36:47 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.variabletypes.SerializablePersistedVariable
    Jun 9, 2010 7:36:47 PM org.hibernate.validator.Version
    INFO: Hibernate Validator 3.1.0.GA
    Jun 9, 2010 7:36:48 PM org.hibernate.cfg.search.HibernateSearchEventListenerRegister enableHibernateSearch
    INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
    Jun 9, 2010 7:36:48 PM org.hibernate.util.NamingHelper getInitialContext
    INFO: JNDI InitialContext properties:{}
    Exception in thread “main” javax.persistence.PersistenceException: [PersistenceUnit: org.drools.persistence.jpa] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
    at com.ml.cm.batchclient.WorkflowPerist.main(WorkflowPerist.java:66)
    Caused by: org.hibernate.HibernateException: Could not find datasource: jdbc/BitronixJTADataSource
    at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:82)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
    at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
    … 4 more

    Like

  7. Hi, exception is resolved thanks. but can you tell me how to map orm.xml file and where to map….if possible please send the snippet code for orm.xml

    Like

  8. Well, orm.xml is a pure hibernate configuration file. You can take a look at the hibernate official documentation for it. By the way, what do you want to map there?
    Greetings.

    PS: is the log telling you that it cannot find a orm.xml file?

    Like

  9. Hi, iam getting trouble with this exception..can please explain me…

    Exception in thread “main” bitronix.tm.resource.ResourceConfigurationException: cannot create JDBC datasource named jdbc/testDS1
    at bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:50)
    at com.ml.cm.batchclient.TestTest.initH2(TestTest.java:108)
    at com.ml.cm.batchclient.TestTest.main(TestTest.java:47)
    Caused by: bitronix.tm.utils.PropertyException: no writeable property ‘URL’ in class ‘com.sybase.jdbc3.jdbc.SybDriver’
    at bitronix.tm.utils.PropertyUtils.getSetter(PropertyUtils.java:292)
    at bitronix.tm.utils.PropertyUtils.setDirectProperty(PropertyUtils.java:185)
    at bitronix.tm.utils.PropertyUtils.setProperty(PropertyUtils.java:51)
    at bitronix.tm.resource.common.XAPool.createXAFactory(XAPool.java:223)
    at bitronix.tm.resource.common.XAPool.(XAPool.java:47)
    at bitronix.tm.resource.jdbc.PoolingDataSource.buildXAPool(PoolingDataSource.java:59)
    at bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:48)
    … 2 more

    Like

  10. hi, its running fine with H2 database, but not with sybase.

    Jun 15, 2010 8:45:26 PM org.hibernate.cfg.annotations.Version
    INFO: Hibernate Annotations 3.4.0.GA
    Jun 15, 2010 8:45:26 PM org.hibernate.cfg.Environment
    INFO: Hibernate 3.3.1.GA
    Jun 15, 2010 8:45:26 PM org.hibernate.cfg.Environment
    INFO: hibernate.properties not found
    Jun 15, 2010 8:45:26 PM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: Bytecode provider name : javassist
    Jun 15, 2010 8:45:26 PM org.hibernate.cfg.Environment
    INFO: using JDK 1.4 java.sql.Timestamp handling
    Jun 15, 2010 8:45:26 PM org.hibernate.annotations.common.Version
    INFO: Hibernate Commons Annotations 3.1.0.GA
    Jun 15, 2010 8:45:26 PM org.hibernate.ejb.Version
    INFO: Hibernate EntityManager 3.4.0.GA
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: com.ml.cm.batchclient.WorkFlow -> WRKFLOW
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.session.SessionInfo
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.session.SessionInfo on table SessionInfo
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.ProcessInstanceInfo
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.processinstance.ProcessInstanceInfo on table ProcessInstanceInfo
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.ProcessInstanceEventInfo
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.processinstance.ProcessInstanceEventInfo on table ProcessInstanceEventInfo
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.WorkItemInfo
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.processinstance.WorkItemInfo on table WorkItemInfo
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.variabletypes.VariableInstanceInfo
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.annotations.EntityBinder bindTable
    INFO: Bind entity org.drools.persistence.processinstance.variabletypes.VariableInstanceInfo on table VariableInstanceInfo
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.variabletypes.JPAPersistedVariable
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.AnnotationBinder bindClass
    INFO: Binding entity from annotated class: org.drools.persistence.processinstance.variabletypes.SerializablePersistedVariable
    Jun 15, 2010 8:45:27 PM org.hibernate.validator.Version
    INFO: Hibernate Validator 3.1.0.GA
    Jun 15, 2010 8:45:27 PM org.hibernate.ejb.Ejb3Configuration configure
    WARNING: hibernate.connection.autocommit = false break the EJB3 specification
    Jun 15, 2010 8:45:27 PM org.hibernate.cfg.search.HibernateSearchEventListenerRegister enableHibernateSearch
    INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
    Jun 15, 2010 8:45:27 PM org.hibernate.util.NamingHelper getInitialContext
    INFO: JNDI InitialContext properties:{}
    Jun 15, 2010 8:45:27 PM org.hibernate.connection.DatasourceConnectionProvider configure
    INFO: Using datasource: jdbc/testDS1
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: RDBMS: H2, version: 1.0.77 (2008-08-16)
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC driver: H2 JDBC Driver, version: 1.0.77 (2008-08-16)
    Jun 15, 2010 8:45:28 PM org.hibernate.dialect.Dialect
    INFO: Using dialect: org.hibernate.dialect.SybaseDialect
    Jun 15, 2010 8:45:28 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
    INFO: Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory
    Jun 15, 2010 8:45:28 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
    INFO: instantiating TransactionManagerLookup: org.hibernate.transaction.BTMTransactionManagerLookup
    Jun 15, 2010 8:45:28 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
    INFO: instantiated TransactionManagerLookup
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Automatic flush during beforeCompletion(): disabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Automatic session close at end of transaction: disabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Scrollable result sets: enabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC3 getGeneratedKeys(): enabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Connection release mode: auto
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Maximum outer join fetch depth: 3
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Default batch fetch size: 1
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Generate SQL with comments: enabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Order SQL updates by primary key: disabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Order SQL inserts for batching: disabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
    INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    Jun 15, 2010 8:45:28 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory
    INFO: Using ASTQueryTranslatorFactory
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query language substitutions: {}
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JPA-QL strict compliance: enabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Second-level cache: enabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query cache: disabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory createRegionFactory
    INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Optimize cache for minimal puts: disabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Structured second-level cache entries: disabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Echoing all SQL to stdout
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Statistics: disabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Deleted entity synthetic identifier rollback: disabled
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Default entity-mode: pojo
    Jun 15, 2010 8:45:28 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Named query checking : enabled
    Jun 15, 2010 8:45:28 PM org.hibernate.impl.SessionFactoryImpl
    INFO: building session factory
    Jun 15, 2010 8:45:28 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
    INFO: Not binding factory to JNDI, no JNDI name configured
    Jun 15, 2010 8:45:28 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: Running hbm2ddl schema export
    Jun 15, 2010 8:45:28 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: exporting generated schema to database
    Jun 15, 2010 8:45:28 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: schema export complete
    Jun 15, 2010 8:45:28 PM bitronix.tm.BitronixTransactionManager logVersion
    INFO: Bitronix Transaction Manager version 1.3.2
    Jun 15, 2010 8:45:28 PM bitronix.tm.Configuration buildServerIdArray
    WARNING: cannot get this JVM unique ID. Make sure it is configured and you only use ASCII characters. Will use IP address instead (unsafe for production usage!).
    Jun 15, 2010 8:45:28 PM bitronix.tm.Configuration buildServerIdArray
    INFO: JVM unique ID:
    Jun 15, 2010 8:45:28 PM bitronix.tm.journal.DiskJournal open
    WARNING: active log file is unclean, previous server crash ?
    Jun 15, 2010 8:45:28 PM bitronix.tm.recovery.Recoverer run
    INFO: recovery committed 0 dangling transaction(s) and rolled back 0 aborted transaction(s) on 1 resource(s) [jdbc/testDS1]
    Hibernate:
    /* insert org.drools.persistence.session.SessionInfo
    */ insert
    into
    SessionInfo
    (dirty, lastModificationDate, rulesByteArray, startDate)
    values
    (?, ?, ?, ?)
    Signalling event..
    Hibernate:
    /* insert org.drools.persistence.processinstance.ProcessInstanceInfo
    */ insert
    into
    ProcessInstanceInfo
    (lastModificationDate, lastReadDate, processId, processInstanceByteArray, startDate, state, OPTLOCK)
    values
    (?, ?, ?, ?, ?, ?, ?)
    reading the reject Object..
    reject object is:class com.ml.cm.batchclient.WorkFlow
    Hibernate:
    /* update
    org.drools.persistence.processinstance.ProcessInstanceInfo */ update
    ProcessInstanceInfo
    set
    lastModificationDate=?,
    lastReadDate=?,
    processId=?,
    processInstanceByteArray=?,
    startDate=?,
    state=?,
    OPTLOCK=?
    where
    processInstanceId=?
    and OPTLOCK=?
    Hibernate:
    /* update
    org.drools.persistence.session.SessionInfo */ update
    SessionInfo
    set
    dirty=?,
    lastModificationDate=?,
    rulesByteArray=?,
    startDate=?
    where
    id=?
    book event is recieved…
    java.lang.NullPointerException
    at org.drools.persistence.processinstance.JPAProcessInstanceManager.removeProcessInstance(JPAProcessInstanceManager.java:82)
    at org.drools.common.AbstractWorkingMemory.removeProcessInstance(AbstractWorkingMemory.java:1724)
    at org.drools.workflow.instance.impl.WorkflowProcessInstanceImpl.setState(WorkflowProcessInstanceImpl.java:186)
    at org.drools.workflow.instance.node.EndNodeInstance.internalTrigger(EndNodeInstance.java:56)
    at org.drools.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:112)
    at org.drools.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:148)
    at org.drools.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:135)
    at org.drools.workflow.instance.node.ActionNodeInstance.triggerCompleted(ActionNodeInstance.java:62)
    at org.drools.workflow.instance.node.ActionNodeInstance.internalTrigger(ActionNodeInstance.java:58)
    at org.drools.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:112)
    at org.drools.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:148)
    at org.drools.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:135)
    at org.drools.workflow.instance.node.JoinInstance.triggerCompleted(JoinInstance.java:152)
    at org.drools.workflow.instance.node.JoinInstance.internalTrigger(JoinInstance.java:65)
    at org.drools.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:112)
    at org.drools.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:148)
    at org.drools.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:135)
    at org.drools.workflow.instance.node.EventNodeInstance.triggerCompleted(EventNodeInstance.java:70)
    at org.drools.workflow.instance.node.EventNodeInstance.internalTrigger(EventNodeInstance.java:62)
    at org.drools.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:112)
    at org.drools.workflow.instance.node.EventNodeInstance.signalEvent(EventNodeInstance.java:50)
    at org.drools.workflow.instance.impl.WorkflowProcessInstanceImpl.signalEvent(WorkflowProcessInstanceImpl.java:272)
    at com.ml.cm.batchclient.RuleFlowTest.main(RuleFlowTest.java:54)
    Exception in thread “main” java.lang.IllegalArgumentException: Named query not found: ProcessInstanceCount
    at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:108)
    at com.ml.cm.batchclient.RuleFlowTest.getCount(RuleFlowTest.java:105)
    at com.ml.cm.batchclient.RuleFlowTest.main(RuleFlowTest.java:60)

    Like

  11. can you please also help me to configure the datasource for “com.sybase.jdbc3.jdbc.SybDriver”. because its giving exception like, could not find xxx datasource…please help me regarding this.
    thanks.

    Like

  12. Hi man, the problem as the stack trace mention is that the ProcessInstanceCount Named query is not found. Probably you are having some problems with sysbase compatibility with JPA. I don’t have a Sysbase installed here to test.
    You can contact me in private and I can give you a hand.

    PS: try to not paste long stacktrace as comments, you can use pastebin.com links.

    Like

  13. HI, can you tell me the deatials about :

    What does the drools persistence model store in terms of :
    • Workflow state.
    • Workflow variable
    • Working memory

    i will be very thank full to you.

    regards
    jp

    Like

  14. About workflow state it stores basically that.. a snapshot about the process state and put it in the database. The process variables can be included in that snapshot or can be externalized and stored separately (in another tables). And about the working memory, it also takes a snapshot of the current status of the working memory and persist it so it can be retrieved from another thread in a later time.
    Greetings.

    Like

  15. can you please explain me:

    which forms of persistence are impacted by whether a class is annotated, unannotated in drools?

    whether persistence writes to DB for every node or only when it gets to wait start in drools?

    can we access a stateless session for rules evaluation from a separate stateful business process instance?

    Like

  16. Hi man,
    yes.. I can answer your questions.
    First of all, it depends on the things that you want to store. for process variables you can use the variable persistence strategies to annotate classes that will be automatically handled by drools. About the persistence mechanism when you run processes, every time that the process reaches a wait state will be persisted in the database.
    About the last question, I’m not sure what do you want to do, but remember that both sessions, stateless and stateful, are java objects and you create any interaction that you want. But before trying to mix stateful and stateless sessions would be nice to understand correctly your use case.
    Greetings,
    hope it helps!

    Like

  17. Hii, Can you give the snippet code for ,whether persistence writes to DB for every node or only when it gets to wait start

    i will be very much thankful to you.

    thanks

    Like

  18. Hi, I don’t understand what you want. As I mention before, drools has it’s own persistence mechanism that know when persist the process (during wait states), and that code it’s internal to the drools framework. You only need to configure it to use the persistence mechanism and you don’t need to worry about how and when drools will persist the information of your business process.
    You can check out the official doc to know how to configure the persistence mechanism in drools flow.
    http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-flow/html_single/index.html#d0e1441

    greetings

    Like

  19. can you please explain me…

    does the variable persistence strategy impact for example the storage of the working memory objects?

    best regards
    kanthi

    Like

  20. Hi,
    No, Variable persistence Strategy is only for variable inside the processes. Not for the working memory objects.
    Why do you need to store that information? what are you trying to achieve?

    Greetings

    Like

  21. If I have a ruleflow with 8 nodes, with none of the nodes as wait states, and no global variables how many records are inserted into the database?

    Like

  22. If you have 8 automatic nodes, without using variables you will only see one record in the database, showing you that you have started and ended a process instance.
    Greetings.

    Like

  23. thanks very much one more last query,,,
    If I add 1000 objects to working memory for the same flow, but no globals, how many inserts are made?

    Like

  24. inserts? if you have wait state a snapshot(binary) of the session will be taken and persisted (using just a sql insert) into a database. But if you have a process without wait states you will not persist nothing from your working memory. Remember that the working memory is just an in memory object that represent the current status of your session. If you insert objects inside the working memory using ksession.insert(object) these objects will be maintained in memory.
    Greetings

    Like

  25. Hi, can we persist the Global variables, if yes please can you give me some idea to go through that?

    best regards
    kanthi

    Like

  26. Hi how are you?
    no you cannot persiste global variables, global variables are oftenly used to make references to services, and make no sense to persist that kind of dynamic/proxy information.
    Why do you want to store a global variable?
    Greetings.

    Like

  27. i am fine, thanks for asking..
    as you said, globals are reference to services. i dont understand what are services, suppose i have object defined in rule as a goblally(global com./../../SomeObject objectType)so cant we persist that object type in DB. please i want to know more about Global variables,can you please give me some docs to refer?

    regards
    kanthi

    Like

  28. Hi man, how are you?
    You can usually use persistence when you have long running business processes. That means that you have to wait for long periods until an activity is completed. If you use human tasks in your processes, you will probably want to use the persistence mechanism.
    Greetings.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s