我尝试使用Activiti& amp;休眠。他们有共同的DB。我首先在Hibernate的帮助下尝试保存同一个实体,然后在Activiti的帮助下保存:
Session session = ((SessionFactory) applicationContext.getBean("sessionFactory")).openSession();
session.beginTransaction();
session.save(client);
execution.setVariable("client", client);
session.getTransaction().commit();
session.close();
问题:
我没有在activiti的ACT_RU_VARIABLE表中看到客户端实体的任何记录。
问题:
如何确保Activiti使用与Hibernate相同的事务?
此外:
的applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- Configuration -->
<context:property-placeholder location="classpath*:*.properties" />
<!-- Annotation based configuration -->
<context:annotation-config />
<context:component-scan base-package="name.krestjaninoff" />
<!-- Data -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5432/activiti-transaction-demo"/>
<property name="username" value="postgres"/>
<property name="password" value="password"/>
</bean>
<!--
Activiti
-->
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="databaseType" value="postgres" />
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<!--<property name="databaseSchemaUpdate" value="create" />-->
<property name="databaseSchemaUpdate" value="true" />
<property name="history" value="audit" />
<property name="jobExecutorActivate" value="false" />
<property name="deploymentResources" value="classpath*:/process/*.bpmn20.xml" />
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine"
factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine"
factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine"
factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine"
factory-method="getManagementService" />
<!--
Hibernate
-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" scope="singleton">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan">
<list>
<value>name.krestjaninoff.activiti.hello.db</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL82Dialect</prop>
<!--<prop key="hibernate.hbm2ddl.auto">create-drop</prop>-->
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" scope="singleton">
<property name="sessionFactory" ref="sessionFactory"/>
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
答案 0 :(得分:0)
答案很简单:只有当进程到达等待,完成或非常异步的任务时,才会将进程变量刷新到DB。并且在处理完成后清理ACT_RU_VARIABLE表。因此,要查看ACT_RU_VARIABLE表中的任何记录,您需要在UserTask期间检查它。