0

我尝试对 Activiti & Hibernate 使用通用事务管理器。他们有共同的数据库。我尝试先在 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相同的事务?

添加:

应用程序上下文.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>
4

1 回答 1

0

答案很简单:只有当进程到达等待状态、完成或启动异步任务时,进程变量才会刷新到 DB。处理完成后清理 ACT_RU_VARIABLE 表。因此,要查看 ACT_RU_VARIABLE 表中的任何记录,您需要在 UserTask 期间检查它。

于 2013-08-21T13:46:06.163 回答