2013-08-20 30 views
0

我嘗試使用Activiti公用事務管理器& Hibernate。他們有共同的數據庫。我試着先與Hibernate的幫助,然後保存在同一實體的Activiti的幫助:Activiti + Hibernate:常見事務管理器

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的使用相同的事務中休眠?

此外:

的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

根據Activiti文檔http://www.activiti.org/userguide/#N12127將實體添加爲流程變量,您需要使用JPA批註配置實體,並且processEngine必須具有對EntityManagerFactory的引用。可能這就是實體沒有被插入到ACT_RU_VARIABLE表中的原因。 – ATMTA

回答

0

答案很簡單:過程變量被刷新到DB只有當流程到達等待stait,成品或勞克異步任務。處理完成後清理ACT_RU_VARIABLE表。因此,要查看ACT_RU_VARIABLE表中的任何記錄,您需要在UserTask期間檢查它。