<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
JBPM4.3 Integration with Spring3.0.1 and Hibernate standalone
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/satishkr">Satish Raju</a> in <i>jBPM Development</i> - <a href="http://community.jboss.org/message/538238#538238">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>I wanted to create a basic standalone application as a test environment for JBPM 4.3 and spring before I used it in my application. So I had the following configuration</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I am using oracle 10g DBMS, Hibernate 3.x, Spring 3.0.1 Release with JBPM 4.3. Here goes my configuration</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>jbpm.cfg.xml</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-xml">
<span class="jive-xml-tag"><?xml version="1.0" encoding="UTF-8"?></span>
<span class="jive-xml-tag"><jbpm-configuration spring="enabled"></span>
<span class="jive-xml-tag"><process-engine-context></span>
    <span class="jive-xml-tag"><repository-service /></span>
    <span class="jive-xml-tag"><repository-cache /></span>
<span class="jive-xml-tag"><execution-service /></span>
<span class="jive-xml-tag"><history-service /></span>
<span class="jive-xml-tag"><management-service /></span>
<span class="jive-xml-tag"><identity-service /></span>
<span class="jive-xml-tag"><task-service /></span>
<span class="jive-xml-tag"><command-service name="txRequiredCommandService"></span>
     <span class="jive-xml-tag"><retry-interceptor /></span>
     <span class="jive-xml-tag"><environment-interceptor /></span>
     <span class="jive-xml-tag"><spring-transaction-interceptor current="true"/></span>
<span class="jive-xml-tag"></command-service></span>
<span class="jive-xml-tag"><object></span>
       <span class="jive-xml-tag"><field name="commandService"></span>
            <span class="jive-xml-tag"><ref object="txRequiredCommandService" /></span>
       <span class="jive-xml-tag"></field></span>
<span class="jive-xml-tag"></object></span>
<span class="jive-xml-tag"><object init="eager" /></span>
<span class="jive-xml-tag"><transaction-context></span>
<span class="jive-xml-tag"><repository-session /></span>
<span class="jive-xml-tag"><db-session /></span>
<span class="jive-xml-tag"><message-session /></span>
<span class="jive-xml-tag"><timer-session /></span>
<span class="jive-xml-tag"><history-sessions/></span>
<span class="jive-xml-tag"><hibernate-session current="true" /></span>
<span class="jive-xml-tag"></transaction-context></span>
<span class="jive-xml-tag"></process-engine-context></span>
<span class="jive-xml-tag"></jbpm-configuration></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>and my spring application context configuration looks like </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag"><?xml version="1.0" encoding="UTF-8"?></span>
<span class="jive-xml-tag"><span><beans xmlns="</span><a class="jive-link-external-small" href="http://www.springframework.org/schema/beans" target="_blank">http://www.springframework.org/schema/beans</a><span>"
     xmlns:tx="</span><a class="jive-link-external-small" href="http://www.springframework.org/schema/tx" target="_blank">http://www.springframework.org/schema/tx</a><span>" xmlns:p="</span><a class="jive-link-external-small" href="http://www.springframework.org/schema/p" target="_blank">http://www.springframework.org/schema/p</a><span>"
     xmlns:util="</span><a class="jive-link-external-small" href="http://www.springframework.org/schema/util" target="_blank">http://www.springframework.org/schema/util</a><span>" xmlns:xsi="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a><span>"
     xmlns:aop="</span><a class="jive-link-external-small" href="http://www.springframework.org/schema/aop" target="_blank">http://www.springframework.org/schema/aop</a><span>" xmlns:context="</span><a class="jive-link-external-small" href="http://www.springframework.org/schema/context" target="_blank">http://www.springframework.org/schema/context</a><span>"
     xsi:schemaLocation="</span><a class="jive-link-external-small" href="http://www.springframework.org/schema/beans" target="_blank">http://www.springframework.org/schema/beans</a><span>
                                   </span><a class="jive-link-external-small" href="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" target="_blank">http://www.springframework.org/schema/beans/spring-beans-3.0.xsd</a><span>
                                   </span><a class="jive-link-external-small" href="http://www.springframework.org/schema/util" target="_blank">http://www.springframework.org/schema/util</a><span>
                                   </span><a class="jive-link-external-small" href="http://www.springframework.org/schema/util/spring-util-3.0.xsd" target="_blank">http://www.springframework.org/schema/util/spring-util-3.0.xsd</a><span>
                                   </span><a class="jive-link-external-small" href="http://www.springframework.org/schema/context" target="_blank">http://www.springframework.org/schema/context</a><span>
                                   </span><a class="jive-link-external-small" href="http://www.springframework.org/schema/context/spring-context-3.0.xsd" target="_blank">http://www.springframework.org/schema/context/spring-context-3.0.xsd</a><span>
                                   </span><a class="jive-link-external-small" href="http://www.springframework.org/schema/util" target="_blank">http://www.springframework.org/schema/util</a><span>
                                   </span><a class="jive-link-external-small" href="http://www.springframework.org/schema/util/spring-util-3.0.xsd" target="_blank">http://www.springframework.org/schema/util/spring-util-3.0.xsd</a><span>
                                   </span><a class="jive-link-external-small" href="http://www.springframework.org/schema/aop" target="_blank">http://www.springframework.org/schema/aop</a><span>
                                   </span><a class="jive-link-external-small" href="http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" target="_blank">http://www.springframework.org/schema/aop/spring-aop-3.0.xsd</a><span>
                                   </span><a class="jive-link-external-small" href="http://www.springframework.org/schema/tx" target="_blank">http://www.springframework.org/schema/tx</a><span>
                                   </span><a class="jive-link-external-small" href="http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" target="_blank">http://www.springframework.org/schema/tx/spring-tx-3.0.xsd</a><span> "></span></span>
     <span class="jive-xml-tag"><bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" /></span>
          
     <span class="jive-xml-tag"><bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" /></span>
     <span class="jive-xml-tag"><context:annotation-config /></span>
     <span class="jive-xml-tag"><tx:advice id="txAdvice" transaction-manager="transactionManager"></span>
          <span class="jive-xml-tag"><tx:attributes></span>
               <span class="jive-xml-tag"><tx:method propagation="REQUIRED" name="*" /></span>
          <span class="jive-xml-tag"></tx:attributes></span>
     <span class="jive-xml-tag"></tx:advice></span>
     
     <span class="jive-xml-comment"><!--<span class="jive-xml-tag"><aop:config></span>
         <span class="jive-xml-tag"><aop:pointcut id="processDeployer" expression="execution(* com.jbpm.DeploymentService.*(..))"/></span>
         <span class="jive-xml-tag"><aop:advisor advice-ref="txAdvice" pointcut-ref="deployProcess"/></span>
       <span class="jive-xml-tag"></aop:config></span>
       
     --></span><span class="jive-xml-tag"><bean id="abstractJbpmProcess" class="com.jbpm.utils.AbstractJbpmProcess" abstract="true"></span>
          <span class="jive-xml-tag"><property name="processEngine" ref="processEngine"/></span>
     <span class="jive-xml-tag"></bean></span>
     
     <span class="jive-xml-tag"><bean id="deploymentService" class="com.jbpm.impl.DeploymentServiceImpl"
          parent="abstractJbpmProcess" /></span>
<span class="jive-xml-tag"></beans></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>So I can use up my processEngine in whichever service I want. So created a simple process definition as shown below</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag"><?xml version="1.0" encoding="UTF-8"?></span>
<span class="jive-xml-tag"><span><process name="GetHomeProcess" xmlns="</span><a class="jive-link-external-small" href="http://jbpm.org/4.3/jpdl" target="_blank">http://jbpm.org/4.3/jpdl</a><span>"></span></span>
   <span class="jive-xml-tag"><start g="16,102,48,48"></span>
      <span class="jive-xml-tag"><transition to="fork"/></span>
   <span class="jive-xml-tag"></start></span>
  
   <span class="jive-xml-tag"><fork g="96,102,48,48" name="fork"></span>
      <span class="jive-xml-tag"><transition g="120,41:" to="send email"/></span>
      <span class="jive-xml-tag"><transition to="call ppl"/></span>
      <span class="jive-xml-tag"><transition g="120,213:" to="book tickets"/></span>
   <span class="jive-xml-tag"></fork></span>
  
   <span class="jive-xml-tag"><state g="176,16,149,52" name="send email"></span>
      <span class="jive-xml-tag"><transition g="606,41:" to="final join"/></span>
   <span class="jive-xml-tag"></state></span>
  
   <span class="jive-xml-tag"><state g="176,100,149,52" name="call ppl"></span>
      <span class="jive-xml-tag"><transition g="377,126:" to="shipping join"/></span>
   <span class="jive-xml-tag"></state></span>
  
   <span class="jive-xml-tag"><state g="176,184,149,58" name="book tickets"></span>
      <span class="jive-xml-tag"><transition g="378,213:" to="shipping join"/></span>
   <span class="jive-xml-tag"></state></span>
  
   <span class="jive-xml-tag"><join g="353,145,48,48" name="shipping join"></span>
      <span class="jive-xml-tag"><transition to="watch movie"/></span>
   <span class="jive-xml-tag"></join></span>
  
   <span class="jive-xml-tag"><state g="431,140,148,52" name="watch movie"></span>
      <span class="jive-xml-tag"><transition g="607,165:" to="final join"/></span>
   <span class="jive-xml-tag"></state></span>
  
   <span class="jive-xml-tag"><join g="583,73,48,48" name="final join"></span>
      <span class="jive-xml-tag"><transition to="end"/></span>
   <span class="jive-xml-tag"></join></span>
  
   <span class="jive-xml-tag"><end g="666,74,48,48" name="end"/></span>
<span class="jive-xml-tag"></process></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The problem would arise when I try to deploy the process </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">        @Test
     <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> testProcessInstantiator() <font color="navy"><b>throws</b></font> FileNotFoundException, JbpmAccessException<font color="navy">{</font>
          String deploymendId= deployProcess();
          <font color="navy"><b>if</b></font>(deploymentService.isProcessDeployed(<font color="red">"GetHomeProcess"</font>)==<font color="navy"><b>false</b></font>)<font color="navy">{</font>
               String deploymendId2= deployProcess();
               System.out.println(<font color="red">"Process 2 deployed = "</font>+deploymendId2);
          <font color="navy">}</font>
          System.out.println(<font color="red">"dep Id = "</font>+deploymendId);
          
     <font color="navy">}</font>
     
     <font color="navy"><b>private</b></font> String deployProcess() <font color="navy"><b>throws</b></font> FileNotFoundException, JbpmAccessException<font color="navy">{</font>
          <font color="navy"><b>return</b></font> deploymentService.deployProcess(<font color="red">"process-defs/HomeProc.jpdl.xml"</font>);
     <font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Deployment service here just helps me deploy the process using JBPM APIs. Doing this shows up an error stack trace as shown</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code">10:47:35,340 FST | [WireContext] creating process-engine
10:47:35,340 FIN | [WireContext] eagerly initializing org.jbpm.pvm.internal.id.DatabaseIdComposer
10:47:35,340 FST | [WireContext] constructing org.jbpm.pvm.internal.id.DatabaseIdComposer
10:47:35,355 FST | [WireContext] initializing org.jbpm.pvm.internal.id.DatabaseIdComposer
10:47:35,355 FST | [WireContext] constructing txRequiredCommandService
10:47:35,355 FST | [WireContext] initializing txRequiredCommandService
10:47:35,355 FST | [SpringProcessEngine] opening jbpm-springPvmEnvironment[31639999]
10:47:35,355 FST | [WireContext] creating transaction
10:47:35,355 FST | [WireContext] org.springframework.transaction.PlatformTransactionManager not found in transaction 1108447
10:47:35,355 FST | [WireContext] org.springframework.transaction.PlatformTransactionManager not found in process-engine 22106538
10:47:35,449 FST | [WireContext] org.hibernate.Session not found in transaction 1108447
10:47:35,449 FST | [WireContext] org.hibernate.Session not found in process-engine 22106538
### EXCEPTION ###########################################
10:47:35,449 INF | [DefaultCommandService] exception while executing command org.jbpm.pvm.internal.cmd.CheckDbCmd@18b9a72
org.jbpm.api.JbpmException: no org.hibernate.Session in current environment
     at org.jbpm.pvm.internal.env.EnvironmentImpl.getFromCurrent(EnvironmentImpl.java:204)
     at org.jbpm.pvm.internal.env.EnvironmentImpl.getFromCurrent(EnvironmentImpl.java:190)
     at org.jbpm.pvm.internal.cmd.CheckDbCmd.execute(CheckDbCmd.java:44)
     at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
     at org.jbpm.pvm.internal.tx.SpringCommandCallback.doInTransaction(SpringCommandCallback.java:45)
     at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
     at org.jbpm.pvm.internal.tx.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:55)
     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.processengine.ProcessEngineImpl.checkDb(ProcessEngineImpl.java:152)
     at org.jbpm.pvm.internal.processengine.SpringProcessEngine.create(SpringProcessEngine.java:70)
     at org.jbpm.pvm.internal.cfg.ConfigurationImpl.buildProcessEngine(ConfigurationImpl.java:92)
     at org.jbpm.pvm.internal.processengine.SpringHelper.createProcessEngine(SpringHelper.java:47)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146)
     at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:540)
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:964)
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:870)
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
     at com.testcases.TestProcessTransaction.setUpBeforeClass(TestProcessTransaction.java:27)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
     at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
### EXCEPTION ###########################################
10:47:35,449 FST | [WireContext] closing transaction...
10:47:35,449 FST | [BasicEnvironment] closing PvmEnvironment[31639999]
10:47:35,449 FST | [PvmEnvironment] closed PvmEnvironment[31639999]
10:47:35,496 INF | [SessionFactoryImpl] closing
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I want every transaction of JBPM to use Spring created transaction, which looks like is happening. If you notice the log statements shown before the stack trace.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code">10:47:35,355 FST | [WireContext] org.springframework.transaction.PlatformTransactionManager not found in transaction 1108447
10:47:35,355 FST | [WireContext] org.springframework.transaction.PlatformTransactionManager not found in process-engine 22106538
10:47:35,449 FST | [WireContext] org.hibernate.Session not found in transaction 1108447
10:47:35,449 FST | [WireContext] org.hibernate.Session not found in process-engine 22106538
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I want to know why this error is showing up. Am I missing anything in my configuration? Is there any documentation or references on how the environments are being used in JBPM? Or is there any way in which I can put the session so that this stand alone application finds it.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>PS: I have also attached my Maven POM.xml, which might help you see the jar dependencies in the project</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Thanks,</p><p>Satish</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/538238#538238">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2035">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>