10 Replies Latest reply on Nov 20, 2012 7:52 AM by kehuagao

    persistence JBPM5.3 on tomcat with mysql

    kehuagao

      Hi,

      EntityManagerFactory emfTask = Persistence.createEntityManagerFactory("org.jbpm.task");

      the above line code works fine,but the below line code do not work.

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

      the error is:

      Could not find datasource: jdbc/jbpm-ds
      javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
      at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
      at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
      at javax.naming.InitialContext.lookup(InitialContext.java:411)
      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.processserver.JbpmAPIUtil.createSession(JbpmAPIUtil.java:257)
      at com.sample.processserver.JbpmAPIUtil.getSession(JbpmAPIUtil.java:238)
      at com.sample.processserver.TaskProcessServlet.init(TaskProcessServlet.java:69)
      at javax.servlet.GenericServlet.init(GenericServlet.java:212)
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
      at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
      at org.apache.catalina.core.StandardService.start(StandardService.java:525)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

      1    10/11 23:36:38,784[main] ERROR sample.processserver.TaskProcessServlet.init  - [PersistenceUnit: org.jbpm.persistence.jpa] Unable to build EntityManagerFactory
      org.hibernate.HibernateException: Could not find datasource

       

      My persistence.xml is :

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
          http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
         
          <persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <jta-data-source>jdbc/jbpm-ds</jta-data-source>
        
              <mapping-file>META-INF/orm.xml</mapping-file>
        
              <class>org.drools.persistence.info.SessionInfo</class>
              <class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>
              <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</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>      
            
              <class>org.jbpm.task.Task</class>
        <class>org.jbpm.task.Comment</class>
        <class>org.jbpm.task.Attachment</class>
        <class>org.jbpm.task.I18NText</class>
        <class>org.jbpm.task.SubTasksStrategy</class>
        <class>org.jbpm.task.Deadline</class>
        <class>org.jbpm.task.Escalation</class>
        <class>org.jbpm.task.Reassignment</class>
        <class>org.jbpm.task.Notification</class>
        <class>org.jbpm.task.BooleanExpression</class>
        <class>org.jbpm.task.User</class>
        <class>org.jbpm.task.PeopleAssignments</class>


              <properties>
                 
                   <!-- H2 dialect -->
                  <!--   <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>   -->
                
                 <!-- Oracle dialect -->
                     <!--   <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/> -->
               
                
                   <!-- mysql dialect -->
                  
                  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                
                  
                  <property name="hibernate.connection.autocommit" value="false"/>
                  <property name="hibernate.max_fetch_depth" value="3"/>
                  <property name="hibernate.hbm2ddl.auto" value="update" />
                  <property name="hibernate.show_sql" value="true" />
                  <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup"/>
              </properties>
           
           
          </persistence-unit>
          <persistence-unit name="org.jbpm.task">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              
              <mapping-file>META-INF/Taskorm.xml</mapping-file>
        
              <class>org.jbpm.task.Attachment</class>
              <class>org.jbpm.task.Content</class>
              <class>org.jbpm.task.BooleanExpression</class>
              <class>org.jbpm.task.Comment</class>
              <class>org.jbpm.task.Deadline</class>
              <class>org.jbpm.task.Comment</class>
              <class>org.jbpm.task.Deadline</class>
              <class>org.jbpm.task.Delegation</class>
              <class>org.jbpm.task.Escalation</class>
              <class>org.jbpm.task.Group</class>
              <class>org.jbpm.task.I18NText</class>
              <class>org.jbpm.task.Notification</class>
              <class>org.jbpm.task.EmailNotification</class>
              <class>org.jbpm.task.EmailNotificationHeader</class>
              <class>org.jbpm.task.PeopleAssignments</class>
              <class>org.jbpm.task.Reassignment</class>
              <class>org.jbpm.task.Status</class>
              <class>org.jbpm.task.Task</class>
              <class>org.jbpm.task.TaskData</class>
              <class>org.jbpm.task.SubTasksStrategy</class>
              <class>org.jbpm.task.OnParentAbortAllSubTasksEndStrategy</class>
              <class>org.jbpm.task.OnAllSubTasksEndParentEndStrategy</class>
              <class>org.jbpm.task.OnAllSubTasksEndParentEndStrategy</class>

              <class>org.jbpm.task.User</class>

              <class>org.drools.persistence.info.SessionInfo</class>
              <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
              <class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>
              <class>org.drools.persistence.info.WorkItemInfo</class>
             

              <properties>
                   <!-- sample H2 configuration 
                  
                  <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
                  <property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
                  <property name="hibernate.connection.url" value="jdbc:h2:mem:droolsflow" />
                  <property name="hibernate.connection.username" value="sa"/>
                  <property name="hibernate.connection.password" value="sasa"/>
                -->
                
                  <!-- Sample Oracle Configuration 
                 
                   <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
                  <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
                  <property name="hibernate.connection.url" value="jdbc:oracle:thin:oracleserver:1521:db" />
                  <property name="hibernate.connection.username" value="nagios"/>
                  <property name="hibernate.connection.password" value="nagios"/>
                  -->
                  
                   <!-- Sample mysql Configuration  -->
                              
                  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                  <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
                  <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jbpm-demo" />
                  <property name="hibernate.connection.username" value="demo"/>
                  <property name="hibernate.connection.password" value="demo"/>
                 
                 
                 
                  <property name="hibernate.connection.autocommit" value="true" />
                  <property name="hibernate.max_fetch_depth" value="3"/>
                  <property name="hibernate.hbm2ddl.auto" value="create" />
                  <property name="hibernate.show_sql" value="false" />
              </properties>
          </persistence-unit>
      </persistence>

        • 1. Re: persistence JBPM5.3 on tomcat with mysql
          ted.pan

          the datasource jdbc/jbpm-ds is not defined. you can define a datasource in the container, or

          just remove the <jta-data-source>jdbc/jbpm-ds</jta-data-source>, and then use the same configuration as org.jbpm.task, by configuring the database connection in the <properties> part of <persistence-unit name="org.jbpm.persistence.jpa"/>

           

           

          Ted

          • 2. Re: persistence JBPM5.3 on tomcat with mysql
            kehuagao

            thank you,Ted.

            It is what I were confused.I try to do  according to the method you provide.it do not work.orginal code is  <jta-data-source>jdbc/testDS1</jta-data-source>,

            the error is  "Could not find datasource: jdbc/jbpm-ds", remove the <jta-data-source>jdbc/jbpm-ds</jta-data-source>, the error is still "Could not find datasource: jdbc/jbpm-ds".

             

            context.xml includes:

            <ResourceLink name="jdbc/jbpm-ds"   type="javax.sql.DataSource"    global="jdbc/jbpm-ds"/>

             

            web.xml includes:

            <resource-ref>
                  <description>DB Connection</description>
                  <res-ref-name>jdbc/jbpm-ds</res-ref-name>
                  <res-type>javax.sql.DataSource</res-type>
                  <res-auth>Container</res-auth>
                  <res-sharing-scope>Shareable</res-sharing-scope>
              </resource-ref>

             

            server.xml includes:

            <Resource auth="Container" name="jdbc/jbpm-ds"    type="javax.sql.DataSource"   password="demo"    driverClassName="com.mysql.jdbc.Driver"    maxIdle="2"    maxWait="5000"    username="demo"    url="jdbc:mysql://localhost:3306/jbpm-demo"    maxActive="4"/>
             

            the datasource has been set up,the error is still "Could not find datasource: jdbc/jbpm-ds".

             

            • 3. Re: persistence JBPM5.3 on tomcat with mysql
              ted.pan

              sorry, I did not check the error message carefully.

               

              I think you should use

              <jta-data-source>java:comp/env/jdbc/jbpm-ds</jta-data-source>

               

              since you have refer to resource in web.xml

               

               

              Ted

              • 4. Re: persistence JBPM5.3 on tomcat with mysql
                kehuagao

                thank you again,Ted.

                 

                I use

                <jta-data-source>java:comp/env/jdbc/jbpm-ds</jta-data-source>

                 

                the error is still "Could not find datasource: jdbc/jbpm-ds".

                • 5. Re: persistence JBPM5.3 on tomcat with mysql
                  ted.pan

                  could you use some test code to check if the datasource configuration is correct?  I don't think the problem is with jBPM configuration now.

                   

                  http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html

                   

                   

                  see the 4. Test code

                   

                   

                   

                  Ted

                  • 6. Re: persistence JBPM5.3 on tomcat with mysql
                    kehuagao

                    it seems that tomcat do not support JTA(datasource or transaction?)

                    but persistence.xml include:

                    <persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
                            <provider>org.hibernate.ejb.HibernatePersistence</provider>
                            <jta-data-source>jdbc/jbpm-ds</jta-data-source>
                    I'll try it

                    • 7. Re: persistence JBPM5.3 on tomcat with mysql
                      ted.pan

                      you can try this http://codepitbull.wordpress.com/2011/07/08/tomcat-7-with-full-jta/

                      to enable the JTA support for Tomcat,

                       

                      or if you are using Spring, you may use this https://community.jboss.org/thread/195386?tstart=0

                      1 of 1 people found this helpful
                      • 8. Re: persistence JBPM5.3 on tomcat with mysql
                        kehuagao

                        I try to use btm on tomcat,it seems that datasource jbpm-ds has been setup successfully.

                        信息: Bitronix Transaction Manager version 2.1.3
                        2012-11-16 22:08:15 bitronix.tm.Configuration buildServerIdArray
                        信息: JVM unique ID: <tomcat7-btm-node0 >
                        2012-11-16 22:08:15 bitronix.tm.journal.DiskJournal open
                        警告: active log file is unclean, did you call BitronixTransactionManager.shutdown() at the end of the last run?
                        2012-11-16 22:08:15 bitronix.tm.resource.ResourceLoader init
                        信息: reading resources configuration from D:\apache-tomcat-7.0.32/conf/btm-resources.properties
                        2012-11-16 22:08:15 bitronix.tm.recovery.Recoverer run
                        信息: recovery committed 0 dangling transaction(s) and rolled back 0 aborted transaction(s) on 1 resource(s) [jdbc/jbpm-ds]

                         

                        but datasource jbpm-ds was not found in my servlet including

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

                         

                        JNDI InitialContext properties:{}
                        2012-11-16 22:08:22 org.hibernate.connection.DatasourceConnectionProvider configure
                        严重: Could not find datasource: jdbc/jbpm-ds
                        javax.naming.NameNotFoundException: Name [jdbc/jbpm-ds] is not bound in this Context. Unable to find [jdbc].
                        at org.apache.naming.NamingContext.lookup(NamingContext.java:820)

                         

                        persistence-unit named "org.jbpm.persistence.jpa" is different from persistence-unit named "org.jbpm.task"  in that there is <jta-data-source>jdbc/jbpm-ds</jta-data-source>.

                        • 9. Re: persistence JBPM5.3 on tomcat with mysql
                          ted.pan

                          hi Kehua,


                          there are some issues with your code


                          1. since you have declared the datasource in web.xm, in persistence.xml, you can use java:comp/env/jdbc/jbpm-ds, instead of jdbc/jbpm-ds, and you don't need to define the connection parameters( driver_class, username and so on) in the persistence.xml, since you are using data source from container.

                            please see the attached persistence.xml for detailed information.


                          2. you can pre-create the database with schema for the persistence unit, org.jbpm.persistence.jpa. But if you want to create it or update it when the persistence unit is created at the first time( see persistence.xml for <property name="hibernate.hbm2ddl.auto" value="update" />), you need to disable the transaction in your TaskProcessServlet's init(), please see the attached TaskProcessServlet.java file.


                          3. you do not need to manually initial the dateasource, please see the TaskProcessServlet.java from line 71 to 86. those lines could be commentted out.


                          4. the default's port for Mina server is 9123, you use MinaTaskServer server = new MinaTaskServer(taskService); to create the mina server, then you should use the port 9123 in your JbpmAPIUtil.java. please see the attached JbpmAPIUtil.java


                          5. in HumanTaskStartupServlet.java. you don't need to start a h2 server there, so you don't need the h2.jar in your classpath.



                          please note, I use different database name and database username, you can adjust the btm-resources.proeprties.  and because the attached file size limitation, I remove hibernate jars from the lib folder, you should add them back if you want to run it.



                          in case if I did not list all the issues, I attached the whole server1 with libraries for you. you can do a comparison with your server1.




                          Ted

                          • 10. Re: persistence JBPM5.3 on tomcat with mysql
                            kehuagao

                            thank you for your help,Ted.

                            the line

                            <property name="hibernate.jndi.class" value="bitronix.tm.jndi.BitronixInitialContextFactory"/>

                            is added into persistence.xml,my issue has been solved.