Activiti with Hibernate

Activiti with Hibernate

 

 

http://forums.activiti.org/en/viewtopic.php?f=6&t=4360

I have solved the problem for our needs.

Now Activiti uses the HibernateTransactionManager and with 
that we can make a full rollback! 
Its not important that Activiti uses MyBatis, 
because after a small research about MyBatis I found out that 
MyBatis support the HibernateTransactionManager.

ApplicationCotext:
Code:
<!-- DataSource Definition -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/activiti"/>
<property name="username" value="root" />
<property name="password" value="root" />
<property name="poolPreparedStatements" value="true" />
<property name="maxActive" value="50" />
<property name="maxIdle" value="10" />
</bean>

<!-- Session Factory Definition -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
...
</bean>


<!-- Hibernate Transaction Manager Definition -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>

<!-- Process Engine Definition -->
<bean id="processEngineConfiguration" 
class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
</bean>


Methods for start and commit a transation
 (all Transactions done after startTransaction are commit after call commit Transaction):
Code:
protected TransactionStatus startTransaction() {
PlatformTransactionManager manager = getTransactionManager();
DefaultTransactionDefinition d = new DefaultTransactionDefinition();
d.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW);

transaction = manager.getTransaction(d);

return transaction;
}

protected void commit(TransactionStatus transaction) {
PlatformTransactionManager manager = getTransactionManager();
manager.commit(transaction);
}

protected void rollback(TransactionStatus transaction) {
PlatformTransactionManager manager = getTransactionManager();
manager.rollback(transaction);
}

private PlatformTransactionManager getTransactionManager() {

return (PlatformTransactionManager) this.appContext
.getBean("transactionManager");
}


I hope this helps anyone who have a problem 
to integrate activiti in a hibernate environment.

P.S.: I think it would be great if this method (or something like that) 
is also found in the activiti doucumentation, 
because lots of projects currently using hibernate for persitences and in the activit
 documentation doesn't exist a guide to integrate activiti in an hibernate environment.

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值