<!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">JBoss 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;">
Spring 3 + jBPM 4.4 - 2 different hibernate sessions
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/mqqla2">mqqla2</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/575384#575384">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hi,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I've strange problem with spring and jbpm. I have code which works sth like that:</p><p>Session session = sessionFactory.getCurrentSession();</p><p>Order order = new Order();</p><p>ExecutionImpl e = processEngine.startProcess(order);</p><p>log(e.getId());   //this logs new process id from jbpm4_execution table, let's say id = 1000</p><p>order.setProcess(e);</p><p>session.save(order);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>order entity has a foreign key to the process it's connected to.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>on saving order in last line I have error from DB the process with id = 1000 does not exist.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I debug jbpm and dig into RepositorySessionImpl - it has hibernate session object encapsulated and it's different than 'my' session object.</p><p>But they both have the same SessionFactory object (the same hashcode etc).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>My spring context xml looks like that (fragment)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><p><bean id="sessionFactory" autowire="default"</p><p><span style="white-space: pre;"> </span>class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"></p><p><span style="white-space: pre;"> </span><property name="dataSource" ref="dataSource" /></p><p><span style="white-space: pre;"> </span><property name="hibernateProperties"></p><p><span style="white-space: pre;"> </span><props></p><p><span style="white-space: pre;"> </span><prop key="hibernate.format_sql">true</prop></p><p><span style="white-space: pre;"> </span><prop key="hibernate.show_sql">true</prop></p><p><span style="white-space: pre;"> </span><prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="white-space: pre;"> </span></props></p><p><span style="white-space: pre;"> </span></property></p><p><span style="white-space: pre;"> </span><property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" /></p><p><span style="white-space: pre;"> </span><property name="mappingLocations"></p><p><span style="white-space: pre;"> </span><list></p><p><span style="white-space: pre;"> </span><value>classpath:jbpm.execution.hbm.xml</value></p><p><span style="white-space: pre;"> </span><value>classpath:jbpm.repository.hbm.xml</value></p><p><span style="white-space: pre;"> </span><value>classpath:jbpm.task.hbm.xml</value></p><p><span style="white-space: pre;"> </span><value>classpath:jbpm.history.hbm.xml</value></p><p><span style="white-space: pre;"> </span><value>classpath:jbpm.identity.hbm.xml</value></p><p><span style="white-space: pre;"> </span></list></p><p><span style="white-space: pre;"> </span></property></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"><span style="white-space: pre;"> </span> </p><p><span style="white-space: pre;"> </span><property name="packagesToScan"></p><p><span style="white-space: pre;"> </span><list></p><p><span style="white-space: pre;"> </span><value>entities.to.scan</value></p><p><span style="white-space: pre;"> </span></list></p><p><span style="white-space: pre;"> </span></property></p><p><span style="white-space: pre;"> </span></bean></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="white-space: pre;"> </span><bean id="dataSource"</p><p><span style="white-space: pre;"> </span>class="org.springframework.jdbc.datasource.DriverManagerDataSource"></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="white-space: pre;"> </span><property name="driverClassName" value="org.hibernate.dialect.PostgreSQLDialect" /></p><p><span style="white-space: pre;"> </span><property name="url" value="jdbc:postgresql://192.168.15.30/jbpm_test" /></p><p><span style="white-space: pre;"> </span><property name="username" value="jbpm" /></p><p><span style="white-space: pre;"> </span><property name="password" value="jbpm" /></p><p><span style="white-space: pre;"> </span></bean></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="white-space: pre;"> </span><!-- enable the configuration of transactional behavior based on annotations --></p><p><span style="white-space: pre;"> </span><tx:annotation-driven transaction-manager="txManager" /></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"><span style="white-space: pre;"> </span> </p><p><span style="white-space: pre;"> </span><bean id="txManager"</p><p><span style="white-space: pre;"> </span>class="org.springframework.jdbc.datasource.DataSourceTransactionManager"></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="white-space: pre;"> </span><property name="dataSource" ref="dataSource" /></p><p><span style="white-space: pre;"> </span></bean></p></p><p><p><bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper"></p><p><span style="white-space: pre;"> </span><property name="jbpmCfg"></p><p><span style="white-space: pre;"> </span><value>jbpm.cfg.xml</value></p><p><span style="white-space: pre;"> </span></property></p><p><span style="white-space: pre;"> </span></bean></p></p><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper"></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><property name="jbpmCfg"></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><value>jbpm.cfg.xml</value></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"></property></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"></bean></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><bean id="processEngine" factory-bean="springHelper"</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">factory-method="createProcessEngine" /></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><bean id="repositoryService" factory-bean="processEngine"</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">factory-method="getRepositoryService" /></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><bean id="executionService" factory-bean="processEngine"</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">factory-method="getExecutionService" /></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><bean id="taskService" factory-bean="processEngine"</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">factory-method="getTaskService" /></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><bean id="historyService" factory-bean="processEngine"</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">factory-method="getHistoryService" /></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><bean id="managementService" factory-bean="processEngine"</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">factory-method="getManagementService" /></div><p><bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" /></p><p><bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" /></p><p><bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService" /></p><p><bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" /></p><p><bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" /></p><p><bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" /></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>and jbpm.cfg.xml looks like that:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><p><jbpm-configuration></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>  <import resource="jbpm.default.cfg.xml" /></p><p>  <import resource="jbpm.businesscalendar.cfg.xml" /></p><p>  <import resource="jbpm.tx.hibernate.cfg.xml" /></p><p>  <import resource="jbpm.jpdl.cfg.xml" /></p><p>  <!-- <import resource="jbpm.bpmn.cfg.xml" />--></p><p>  <import resource="jbpm.identity.cfg.xml" /></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>  <!-- Job executor is excluded for running the example test cases. --></p><p>  <!-- To enable timers and messages in production use, this should be included. --></p><p>  <!--</p><p>  <import resource="jbpm.jobexecutor.cfg.xml" /></p><p>  --></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>  <process-engine-context></p><p><span style="white-space: pre;"> </span><command-service name="newTxRequiredCommandService"></p><p><span style="white-space: pre;"> </span><retry-interceptor /></p><p><span style="white-space: pre;"> </span><environment-interceptor policy="requiresNew" /></p><p><span style="white-space: pre;"> </span><spring-transaction-interceptor</p><p><span style="white-space: pre;"> </span>policy="requiresNew"  /></p><p><span style="white-space: pre;"> </span></command-service></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="white-space: pre;"> </span><command-service name="txRequiredCommandService"></p><p><span style="white-space: pre;"> </span><retry-interceptor /></p><p><span style="white-space: pre;"> </span><environment-interceptor /></p><p><span style="white-space: pre;"> </span><spring-transaction-interceptor /></p><p><span style="white-space: pre;"> </span></command-service></p><p><span style="white-space: pre;"> </span></process-engine-context></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="white-space: pre;"> </span><transaction-context></p><p>        <transaction type="spring" /></p><p>        <hibernate-session current="true" /></p><p>    </transaction-context></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p></jbpm-configuration></p><div> </div><div>Where's my mistake? It looks there is no shared transaction between my code and jbpm code. All methods are marked @Transactional in my code, and stack trace shows tx interceptors is up and running. But I still don't know why I have 2 different sessions and 1 common sessionfactory.</div><div> </div><div>any help would be appreciated <span> :) </span></div><div> </div><div>regards</div><div>mk</div><div> </div></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/575384#575384">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>