3 Replies Latest reply on May 13, 2011 3:39 AM by melc

    jBPM 5.0.1 Configuring persistence

    jdh

      I am converting my jBPM 4.4 code over to use 5.0.1 and am trying to configure persistence.  When I run my unit tests to see if everything is working as it did in 4.4 I am getting this error:

       

      No Persistence provider for EntityManager named org.jbpm.persistence.jpa

       

      See the end for the full stack trace.  I have been following the user guide and configured a datasource.xml file and set up the EntityManagerFactory and used it in the creation of the KnowledgeSession.  What am I still missing?  Any help would be appreciated.

       

      Jim

       

            EntityManagerFactory emf =

                Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" );

            Environment env = KnowledgeBaseFactory.newEnvironment();

            env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );

            Collection<StatefulKnowledgeSession> ksConfigs =

                                               kbase.getStatefulKnowledgeSessions();

            if (!ksConfigs.isEmpty()) {

              KnowledgeSessionConfiguration[] sessionArray =

                               (KnowledgeSessionConfiguration[])ksConfigs.toArray();

              if (ksConfigs.size() == 1) {

                sessionConfig = sessionArray[0];

              }

              if (ksConfigs.size() > 1) {

                throw new Exception("More than one KnowledgeSessionConfiguration" +

                  " object exists.  We were only expecting one");

              }

            }

       

            if (ksession == null) {

             ksession = kbase.newStatefulKnowledgeSession(sessionConfig, env );

            }  

       

      Stack Trace:

       

      "Exception in constructor: testStartProcess (java.lang.ExceptionInInitializerError

      at xxxxxxxxxxxxxxxxxxxxxxxxxx.SelectiveConsumerTest.&lt;init&gt;(Unknown Source)

      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

      at junit.framework.TestSuite.createTest(TestSuite.java:61)

      at junit.framework.TestSuite.addTestMethod(TestSuite.java:283)

      at junit.framework.TestSuite.&lt;init&gt;(TestSuite.java:146)

      at org.junit.internal.runners.JUnit38ClassRunner.&lt;init&gt;(JUnit38ClassRunner.java:67)

      at org.junit.internal.builders.JUnit3Builder.runnerForClass(JUnit3Builder.java:14)

      at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)

      at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)

      at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)

      at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)

      at junit.framework.JUnit4TestAdapter.&lt;init&gt;(JUnit4TestAdapter.java:31)

      at junit.framework.JUnit4TestAdapter.&lt;init&gt;(JUnit4TestAdapter.java:24)

      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

      at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:386)

      at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:911)

      at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:768)

      Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named org.jbpm.persistence.jpa

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

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

      at xxxxxxxxxxxxxxxxxxxxxxxxxx.SelectiveConsumer&lt;init&gt;(Unknown Source)

      at xxxxxxxxxxxxxxxxxxxxxxxxxx.SelectiveConsumer&lt;clinit&gt;(Unknown Source)

        • 1. jBPM 5.0.1 Configuring persistence
          melc

          Hello Jim,

          It seems that the jpa persistence provider cannot be found. Have you created a persistence.xml in your classpath as described in,  http://docs.jboss.org/jbpm/v5.0/userguide/ch08.html  ?

          • 2. jBPM 5.0.1 Configuring persistence
            jdh

            Thanks Chris,

            Yes, I have followed the User Guide very closely and have a persistence.xml which is copied to the root classes directory on each build so it's in the classpath.  If I have set either of these up wrong I would really appreciate someone pointing out my mistake!  My app defines the datasource as:

             

                  PoolingDataSource ds = new PoolingDataSource();

                  ds.setUniqueName("jdbc/sc4DS1");

                  ds.setClassName("org.postgresql.Driver");

                  ds.setMaxPoolSize(3);

                  ds.setAllowLocalTransactions(true);

                  ds.getDriverProperties().put("user", "jbpm");

                  ds.getDriverProperties().put("password", "PasswordValue");

                  ds.getDriverProperties().put("URL", "jdbc:postgresql://ServerName:5432/jbpm");

                  ds.init();

             

             

            <?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.drools.persistence.jpa" transaction-type="JTA">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                <jta-data-source>java:jdbc/sc4DS1</jta-data-source>       
                <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
                <class>org.drools.persistence.info.SessionInfo</class>
                <class>org.drools.persistence.info.WorkItemInfo</class>
                <properties>
                  <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>        
                  <property name="hibernate.max_fetch_depth" value="3"/>
                  <property name="hibernate.hbm2ddl.auto" value="validate" />
                  <property name="hibernate.show_sql" value="false" />
                  <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
                </properties>       
              </persistence-unit>
            </persistence>

            • 3. jBPM 5.0.1 Configuring persistence
              melc

              Hi Jim,

              Are you running on an application server?

               

              If yes have you tried to create a datasource in the applicaiton server ? If you're using jboss then you could use the testDS1-ds.xml , the contents of which are mentioned in http://docs.jboss.org/jbpm/v5.0/userguide/ch08.html .

               

              If that does not work i would suggest to test the rest of your configuration with the default  h2 configuration regarding persistence and if it works then we could focus on the postgres requirements/properties, otherwise something is wrong with the rest of the configuration....  does this make sense ?