6 Replies Latest reply on Oct 16, 2008 11:32 PM by li gang

    jBPM 3.2 using CMT

    Marcus Schmidke Newbie

      Hello all,

      the following post deals with one simple question: do I have to do something to tell JBoss to include the jBPM hibernate.cfg.xml when he bootstraps his own CMP hibernate configuration?

      In detail:

      I'm trying to get jBPM 3.2 running in a JBoss 4.2 application server. Mainly, I'm evaluating the question: should I use EJB3 entity beans or pure hibernate beans beneath jBPM (I want to use the same schema / datasource / transactions and I want to have own beand as process variables).

      To achieve this, I've followed the wiki article http://wiki.jboss.org/wiki/Wiki.jsp?page=Jbpm32UsingCMT.

      Unfortunately, it does not work at all. I've followed the instructions in the wiki article with absolutely no success.

      My first disappointment was "createSchema", which only gives "You cannot commit during a managed transaction". I've googled a lot and finally found a french article which told me to call createSchema with a jbpmContext parameter, after having put an injected hibernate session into this context. Sounds plausible, but unfortunately, createSchema can't be called with a context parameter. Only with a context name parameter, which doesn't help much. Don't know which version of jBPM was used in France.

      Ok, creating the schema is not that important. I've created the schema using the supplied scripts and skipped this step.

      Next step was trying to deploy a process definition. Again I wrote in my stateless session bean:

      @PersistenceContext
      private Session session;
      public void deployProcessDefinition() {
       ProcessDefinition processDefinition = ProcessDefinition
       .parseXmlString("<process-definition name='hello world'>"
       + " <start-state name='start'>"
       + " <transition to='s' />" + " </start-state>"
       + " <state name='s'>" + " <transition to='end' />"
       + " </state>" + " <end-state name='end' />"
       + "</process-definition>");
      
       JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
       JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
       jbpmContext.setSession(session);
       jbpmContext.deployProcessDefinition(processDefinition);
       jbpmContext.close();
      }
      

      Of course, I get an error, it's the following:

      Named query not known: GraphSession.findLatestProcessDefinitionQuery

      Some lines up in the log, he told me:

      14:34:29,065 INFO [Configuration] Reading mappings from resource : org/jbpm/db/hibernate.queries.hbm.xml

      , and there is absolutely nothing suspicious in the log (I think).

      It sounds to me that he has build a second Hibernate config, but setSession forces him to use JBoss' Hibernate config which does not contain the jBPM stuff.

      I've taken the jbpm.cfg.xml and hibernate.cfg.xml from jbpm-enterprise.jar with only little modifications (in hibernate, I've put my own datasource, and in jbpm I changed the non-existent message and scheduler entries.

      Altogether packaged in a rather basic EAR.

      Can anybody help me?

      Marcus.

        • 1. Re: jBPM 3.2 using CMT
          Marcus Schmidke Newbie

          Commenting myself ...

          I've put

          <property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml" />

          in my persistence.xml. Don't know if it has some other side effects, but for a first try, it seems to work ...

          This solves the problem that JBoss' Hibernate did not know about jBPM entities.

          Still unsolved is the problem how to prevent jBPM from creating a second unused Hibernate configuration. Perhaps a simple configuration, we will see.


          • 2. Re: jBPM 3.2 using CMT
            Marcus Schmidke Newbie

            Hmmm ...
            Using DbPersistenceServiceFactory instead of JtaDbPersistenceServiceFactory seems to help ...

            But what is JtaDbPersistenceServiceFactory for?

            I'm totally confused ...

            • 3. Re: jBPM 3.2 using CMT
              Marcus Schmidke Newbie

              Ok,

              binding JBoss' Hibernate Session Factory to JNDI via persistence.xml:

              <persistence-unit name="MyEJBPU" transaction-type="JTA">
               <jta-data-source>java:jdbc/myDS</jta-data-source>
               <properties>
               <property name="hibernate.dialect"
               value="org.hibernate.dialect.Oracle9iDialect" />
               <property name="hibernate.hbm2ddl.auto" value="update" />
               <property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml" />
               <property name="hibernate.session_factory_name" value="java:/MyFactory" />
               <property name="hibernate.use_sql_comments" value="true" />
               <property name="hibernate.show_sql" value="true" />
               </properties>
              </persistence-unit>
              


              and referencing this in jbpm.cfg.xml:
              <jbpm-context>
               <service name="persistence">
               <factory>
               <bean class="org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory">
               <field name="sessionFactoryJndiName">
               <string value="java:/Argos3Factory" />
               </field>
               </bean>
               </factory>
               </service>
              ...
              


              seems to help.

              And never forget to inject the container's Hibernate session into the JbpmContext.

              • 4. Re: jBPM 3.2 using CMT
                Marcus Schmidke Newbie

                Ups ... tried to anonymize but missed something ... of course it is

                 <string value="java:/MyFactory" />
                


                • 5. Re: jBPM 3.2 using CMT
                  Javier García Newbie

                  Hi!

                  First of all, sorry for my english, it isn't my native language.

                  I have the same problem that MSchmidke when the jbpm configuration is being created with spring.

                  My jbpm.cfg.xml file is :

                  <jbpm-configuration>
                  
                   <!--
                   The default configurations can be found in org/jbpm/default.jbpm.cfg.xml
                   Those configurations can be overwritten by putting this file called
                   jbpm.cfg.xml on the root of the classpath and put in the customized values.
                   -->
                  
                   <jbpm-context name='default.jbpm.context'>
                   <service name='persistence'
                  factory='org.jbpm.persistence.db.DbPersistenceServiceFactory' />
                   <service name="tx" factory="org.jbpm.tx.TxServiceFactory" />
                   </jbpm-context>
                  
                   <string name='resource.business.calendar' value='org/jbpm/calendar/jbpm.business.calendar.properties' />
                   <string name='resource.default.modules' value='org/jbpm/graph/def/jbpm.default.modules.properties' />
                   <string name='resource.converter' value='org/jbpm/db/hibernate/jbpm.converter.properties' />
                   <string name='resource.action.types' value='org/jbpm/graph/action/action.types.xml' />
                   <string name='resource.node.types' value='org/jbpm/graph/node/node.types.xml' />
                   <string name='resource.parsers' value='org/jbpm/jpdl/par/jbpm.parsers.xml' />
                   <string name='resource.varmapping' value='org/jbpm/context/exe/jbpm.varmapping.xml' />
                  
                   <int name='jbpm.byte.block.size' value="1024" singleton="true" />
                   <bean name='jbpm.task.instance.factory' class='org.jbpm.taskmgmt.impl.DefaultTaskInstanceFactoryImpl' singleton='true' />
                   <bean name='jbpm.variable.resolver' class='org.jbpm.jpdl.el.impl.JbpmVariableResolver' singleton='true' />
                  
                  
                  </jbpm-configuration>
                  


                  And my spring applicationContext is like that
                  <?xml version="1.0" encoding="UTF-8"?>
                  <beans xmlns="http://www.springframework.org/schema/beans"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:aop="http://www.springframework.org/schema/aop"
                   xsi:schemaLocation="http://www.springframework.org/schema/beans
                   http://www.springframework.org/schema/beans/spring-beans.xsd
                   http://www.springframework.org/schema/aop
                   http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
                  
                  
                   <bean id="sessionFactory2" autowire-candidate="false"
                   class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                   <property name="dataSource" ref="dataSource" />
                   <property name="mappingLocations">
                   <value>classpath:hibernate.cfg.xml</value>
                   </property>
                   <property name="hibernateProperties">
                   <props>
                   <prop key="hibernate.dialect">
                   org.hibernate.dialect.HSQLDialect
                   </prop>
                   <prop key="hibernate.cache.provider_class">
                   org.hibernate.cache.EhCacheProvider
                   </prop>
                   <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
                   </props>
                   </property>
                   </bean>
                  
                   <!-- jBPM configuration -->
                   <bean id="jbpmConfiguration"
                   class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
                   <property name="configuration" value="classpath:jbpm.cfg.xml"/>
                   <property name="sessionFactory" ref="sessionFactory2" />
                   <property name="processDefinitionsResources">
                   <list>
                   <value>classpath:EjemploSpring/processdefinition.xml</value>
                   </list>
                   </property>
                   <property name="createSchema" value="true"/>
                   </bean>
                  
                  </beans>
                  


                  When Spring is initializating the beans, i have the following error:

                   ...
                  Caused by: org.hibernate.MappingException: Named query not known: GraphSession.findLatestProcessDefinitionQuery
                   at org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:70)
                   at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1260)
                   at org.jbpm.db.GraphSession.findLatestProcessDefinition(GraphSession.java:151)
                   ... 37 more
                  


                  I have red the hole post but i don't understand the answer of MSchmidke. I'm using a DbPersistenceServiceFactory but it doesn't solve the problem.

                  I willl be very greatful if you answer me

                  Thanks a lot

                  • 6. Re: jBPM 3.2 using CMT
                    li gang Newbie

                    MSchmidke,you said you can't createSchema,it's possiblely because you use oracle database.I remembered that there's a rule about oracle database.The rule is :in a transaction,you can't commit DDL statements.
                    Sorry ,I can only tell you so litter stuff.I am not good at EJB3.