3 Replies Latest reply on Mar 3, 2013 5:44 PM by Csaba K

    JPAWorkingMemoryDbLogger NullPointerException

    Csaba K Newbie

      Hi,

       

      I am a newbie JBPM user and I would like to get history log.

      I use JBPM v5.3,I tried it with a sapmle process, and I get the Exception below:

       

      Exception in thread "main" java.lang.NullPointerException

          at org.jbpm.process.audit.JPAWorkingMemoryDbLogger.addProcessLog(JPAWorkingMemoryDbLogger.java:90)

          at org.jbpm.process.audit.JPAWorkingMemoryDbLogger.logEventCreated(JPAWorkingMemoryDbLogger.java:65)

          at org.drools.audit.WorkingMemoryLogger.filterLogEvent(WorkingMemoryLogger.java:196)

          at org.drools.audit.WorkingMemoryLogger.beforeProcessStarted(WorkingMemoryLogger.java:421)

          at org.drools.event.ProcessEventSupport.fireBeforeProcessStarted(ProcessEventSupport.java:40)

          at org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:167)

          at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:138)

          at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:130)

          at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1077)

          at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:315)

          at com.sample.ProcessMain.main(ProcessMain.java:25)

       

      The java code:

      public class ProcessMain {

       

          public static final void main(String[] args) throws Exception {

            

              KnowledgeBase kbase = readKnowledgeBase();

              StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

              JPAWorkingMemoryDbLogger logger = new JPAWorkingMemoryDbLogger(ksession);

              ksession.startProcess("com.sample.bpmn.hello");

              logger.dispose();

          }

       

       

          private static KnowledgeBase readKnowledgeBase() throws Exception {

              KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

              kbuilder.add(ResourceFactory.newClassPathResource("sample.bpmn"), ResourceType.BPMN2);

              return kbuilder.newKnowledgeBase();

          }

         

      }

       

      I use an in-memory H2 database, I created the three tables (process,node and variable log), the JTA datasource

      is binded to this database in the jbpm-ds.xml file. My persistence.xml is the following:

       

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

      <persistence version="1.0"

                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence

                                       http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd

                                       http://java.sun.com/xml/ns/persistence/orm

                                       http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"

                   xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"

                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                   xmlns="http://java.sun.com/xml/ns/persistence">

       

        <persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">

          <provider>org.hibernate.ejb.HibernatePersistence</provider>

          <jta-data-source>java:jboss/datasources/jbpmDS</jta-data-source>      

          <mapping-file>META-INF/JBPMorm.xml</mapping-file>

          <mapping-file>META-INF/ProcessInstanceInfo.hbm.xml</mapping-file>

       

          <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>

          <class>org.drools.persistence.info.SessionInfo</class>

          <class>org.drools.persistence.info.WorkItemInfo</class>

       

          <class>org.jbpm.process.audit.ProcessInstanceLog</class>

          <class>org.jbpm.process.audit.NodeInstanceLog</class>

          <class>org.jbpm.process.audit.VariableInstanceLog</class>

       

          <properties>

            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>

            <property name="hibernate.max_fetch_depth" value="3"/>

       

            <property name="hibernate.hbm2ddl.auto" value="update" />

            <property name="hibernate.show_sql" value="false" />

       

            <!-- for AS7 -->

            <property name="hibernate.transaction.manager_lookup_class" value="org.jbpm.integration.console.JBPMTransactionManager" />

          </properties>       

        </persistence-unit>

         

      </persistence>

       

      Thanks for your help!

       

      Csaba

        • 1. Re: JPAWorkingMemoryDbLogger NullPointerException
          Maciej Swiderski Master

          you need to create persistence session via JPAKnowledgeSession class instead of getting one directly from kbase. That is probably the case as there is no environment with entity manager factory in it. Environment is taken from ksession inside JPAWorkingMemoryDBLogger. Take a look at documentation for details hot to crate persistent session.

           

          HTH

          1 of 1 people found this helpful
          • 2. Re: JPAWorkingMemoryDbLogger NullPointerException
            Csaba K Newbie

            Thank you for the answer!

             

            I tried to make it (following the tutorial) and I try to use my jbpm-installer/db/persistance.xml, but it seems, that entitymanager does not see it.

            The code:

               KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

                    //    kbuilder.add(new ClassPathResource("ruleflow.rf"), ResourceType.DRF);

             

                        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();

                        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

                        // create a new session

                      

                        EntityManagerFactory emf = Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" );

             

            I got this error message, if I delete jbpm.test.5.3.Final.jar from the libraries. (I do it, because if I don't Entitymanager uses its persistance.xml).:

            log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).

            log4j:WARN Please initialize the log4j system properly.

            log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

            Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named org.jbpm.persistence.jpa

                at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:56)

                at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)

                at com.sample.ProcessMain.main(ProcessMain.java:30)

             

            I created also a jBPM.properties file.

            What config file should I change, or what variable should I set?

             

            Br,

             

            Csaba

            • 3. Re: JPAWorkingMemoryDbLogger NullPointerException
              Csaba K Newbie

              If I do not remove jbpm.test.5.3.Final.jar from library I get this exception also in the line where I try to create EntityManagerFactory:

               

              103/03 23:40:19,096[main] ERROR hibernate.connection.DatasourceConnectionProvider.configure  - Could not find datasource: jdbc/jbpm-ds

              javax.naming.NameNotFoundException: unable to find a bound object at name 'jdbc/jbpm-ds'

              at bitronix.tm.jndi.BitronixContext.lookup(BitronixContext.java:83)
              at javax.naming.InitialContext.lookup(InitialContext.java:409)
              at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
              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.buildSettingsInternal(Configuration.java:2119)
              at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
              at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
              at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
              at com.sample.ProcessMain.main(ProcessMain.java:31)

              Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: org.jbpm.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:52)
              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
              at com.sample.ProcessMain.main(ProcessMain.java:31)

              Caused by: org.hibernate.HibernateException: Could not find datasource

              at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:79)
              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.buildSettingsInternal(Configuration.java:2119)
              at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
              at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
              ... 4 more

              Caused by: javax.naming.NameNotFoundException: unable to find a bound object at name 'jdbc/jbpm-ds'

              at bitronix.tm.jndi.BitronixContext.lookup(BitronixContext.java:83)
              at javax.naming.InitialContext.lookup(InitialContext.java:409)
              at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
              ... 12 more

               

              It's getting very annoying, I've spent hours with this error..

               

              Thank you for your help!

               

              Csaba