5 Replies Latest reply on Dec 25, 2009 7:30 PM by kukeltje

    Exception: couldn't acquire block of ids while deploying process

    deady

      I use jbpm4 + spring integration in jboss-4.0.4.GA.

      I use embedded hsqldb for jbpm hibernate:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <datasources>
      
         <local-tx-datasource>
            <jndi-name>jbpm-ds</jndi-name>
            <connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}jbpmDB</connection-url>
            <driver-class>org.hsqldb.jdbcDriver</driver-class>
            <user-name>sa</user-name>
            <password></password>
            <min-pool-size>1</min-pool-size>
            <max-pool-size>5</max-pool-size>
            <idle-timeout-minutes>0</idle-timeout-minutes>
            <track-statements/>
            <!--
            <security-domain>HsqlDbRealm</security-domain>
            -->
            <prepared-statement-cache-size>32</prepared-statement-cache-size>
            <metadata><type-mapping>Hypersonic SQL</type-mapping></metadata>
            <depends>jboss:service=Hypersonic,database=jbpmDB</depends>
         </local-tx-datasource>
      
         <mbean code="org.jboss.jdbc.HypersonicDatabase"
           name="jboss:service=Hypersonic,database=jbpmDB">
           <attribute name="Database">jbpmDB</attribute>
           <attribute name="InProcessMode">true</attribute>
         </mbean>
      
      </datasources>
      
      

       

      <?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:context="http://www.springframework.org/schema/context"
             xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
      
      
          <bean id="jbpmDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
              <property name="jndiTemplate" ref="jndiTemplate"/>
              <property name="jndiName" value="java:/jbpm-ds"/>
          </bean>
      
          <bean id="jbpmSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
              <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>
              <property name="configLocation" value="hibernate.cfg.xml"/>
              <property name="mappingLocations">
                  <list>
                      <value>classpath:jbpm.execution.hbm.xml</value>
                      <value>classpath:jbpm.repository.hbm.xml</value>
                      <value>classpath:jbpm.task.hbm.xml</value>
                      <value>classpath:jbpm.history.hbm.xml</value>
                      <value>classpath:jbpm.identity.hbm.xml</value>
                  </list>
              </property>
              <property name="dataSource" ref="jbpmDataSource"/>
          </bean>
      
      </beans>
      

       

      When I try to deploy process:

       

          @PostConstruct
          public void setupProcessDefinitions() {
              for (String processDefinition : processDefinitions) {
                  NewDeployment deployment = repositoryService.createDeployment();
                  deployment.addResourceFromClasspath(processDefinition);
                  deployment.deploy();
              }
          }
      
      

       

      i recieve

      Caused by: org.jbpm.api.JbpmException: couldn't acquire block of ids
          at org.jbpm.pvm.internal.id.DatabaseDbidGenerator.getNextId(DatabaseDbidGenerator.java:65)
          at org.jbpm.pvm.internal.repository.RepositorySessionImpl.deploy(RepositorySessionImpl.java:56)
          at org.jbpm.pvm.internal.cmd.DeployCmd.execute(DeployCmd.java:47)
          at org.jbpm.pvm.internal.cmd.DeployCmd.execute(DeployCmd.java:33)
          at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
          at org.jbpm.pvm.internal.spring.CommandTransactionCallback.doInTransaction(CommandTransactionCallback.java:50)
          at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
          at org.jbpm.pvm.internal.tx.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:77)
          at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
          at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
          at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
          at org.jbpm.pvm.internal.repository.DeploymentImpl.deploy(DeploymentImpl.java:91)
          at workflow.WorkflowService.setupProcessDefinitions(WorkflowService.java:50)
      
      

       

       

       

      using debug, I see that this is because

       

      package org.jbpm.pvm.internal.id;
      ...
      public class AcquireDbidBlockCmd implements Command<Long> {
      ...
        public Long execute(Environment environment) throws Exception {
          Session session = environment.get(Session.class);
          
          PropertyImpl property = (PropertyImpl) session.createQuery(
              "select property " +
              "from "+PropertyImpl.class.getName()+" as property " +
              "where property.key = '"+PropertyImpl.NEXT_DBID_KEY+"'"
          ).uniqueResult();
          
          String nextIdText = property.getValue();
      
      

      this query returns null. (This table contains no records at all)

       

      But all thing works when I use Mysql with InnoDB.

       

      How can I resolve this issue?

        • 1. Re: Exception: couldn't acquire block of ids while deploying process
          deady

          According to http://docs.jboss.com/jbpm/v4/userguide/html_single/ I must create init params with script

           

          2.10.1. Creating or dropping the database schema

          To create the schema, run target create.jbpm.schema in the ${jbpm.home}/install directory. Apart from creating tables and constraints, the mentioned target will initialize table JBPM4_PROPERTY with the current engine version (key db.version) and the ID generator base value (key next.dbid).

          To drop the schema, simply run target drop.jbpm.schema. Be aware that this operation will destroy any data present in the jBPM tables.

          So in spring conf with

                  <property name="hbm2ddl.auto">create-drop</property>

           

          how do I automate this process?

          • 2. Re: Exception: couldn't acquire block of ids while deploying process
            deady

            DB conf is bootstrapped in

            org.jbpm.pvm.internal.cmd.CheckDbCmd

             

                // if table JBPM4_PROPERTIES doesn't exist, 
                if (!PropertyImpl.propertiesTableExists(session)) {
                  if (!executionTableExists(session)) {
                    // tell users to run create.schema
                    throw new JbpmException("no jBPM DB schema: no JBPM4_EXECUTION table.   Run the create.jbpm.schema target first in the install tool.");
                    
                  } else {
                    // tell users to run upgrade
                    throw new JbpmException("jBPM DB schema not in sync with library version: no JBPM4_PROPERTIES table.   Run the upgrade target first in the install tool.");
                  }
                  
                } else {
                  Long nextDbid = PropertyImpl.getNextDbid(session);
                  // if there is no next.dbid property specified 
                  if (nextDbid==null) {
                    // (this only happens in the test suite)
                    // initialize the dbid property.  
                    PropertyImpl.setNextDbid(session, 1);
                  }
            
            

            I wonder why this doesn't work? Maybe transaction issue?

            • 3. Re: Exception: couldn't acquire block of ids while deploying process
              deady
              This bootstrap is called from SpringConfiguration.buildProcessEngine(). But it is never called
              • 4. Re: Exception: couldn't acquire block of ids while deploying process
                deady

                Got it. It was IOC issue. jbpmConfiguration was injected into workflowService, which deployed processes in @PostConstruct method.

                    <bean id="processEngine" factory-bean="jbpmConfiguration" factory-method="buildProcessEngine"/>
                
                

                This string causes jbpm to bootstrap but it is to late.

                 

                Method buildProcessEngine() must be marked as init method or depended beans must be after processEngine in spring configuration.

                • 5. Re: Exception: couldn't acquire block of ids while deploying process
                  kukeltje
                  I love people answering their own questions.... but thanks for reporting ;-)