AnsweredAssumed Answered

Pass hibernateSessionFactory to Activiti engine configs

Question asked by fritz128 on Sep 27, 2013
Latest reply on Sep 27, 2013 by fritz128
Problem disclosure
I've read that to achieve common transaction for Hibernate and Activiti I should pass HibernateTransactionManager to ProcessEngineConfiguration bean.

When I doing so, I can check in debuger in ProcessEngineImpl constructor:
((SpringProcessEngineConfiguration) processEngineConfiguration).getTransactionManager() = org.springframework.orm.hibernate4.HibernateTransactionManager


But
processEngineConfiguration.getCustomSessionFactories() = null

processEngineConfiguration.getSessionFactories() = java.util.HashMap size = 27

27 session factories, all from org.activiti.engine.impl package with no mean of custom hibernate sessionFactory


What a statement:
I suggest that problem with common transaction for Hibernate and Activiti lies in that fact that processEngineConfiguration.getSessionFactories() doesn't contain org.springframework.orm.hibernate4.LocalSessionFactoryBean

Question
How can I set hibernate's sessionFactory into processEngineConfigurations. I hope I can do it in xml.

My configs

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <tx:annotation-driven  transaction-manager="transactionManager"/>

    <!– 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="sessionFactories"  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!–>
        <property name="transactionsExternallyManaged" value="true"/>
      <!–<property name="databaseSchemaUpdate" value="create" />–>
        <property name="databaseSchemaUpdate" value="true"/>
        <property name="history" value="full" />
      <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" />
    <bean id="identityService" factory-bean="processEngine"
          factory-method="getIdentityService" />

    <!–
       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</prop>–>
            </props>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" scope="singleton">
        <property name="sessionFactory">
            <ref local="sessionFactory" />
        </property>
        <property name="dataSource">
            <ref local="dataSource" />
        </property>
    </bean>
</beans>

Outcomes