cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti+Spring+Hibernate: common transaction manager

jolo_
Champ on-the-rise
Champ on-the-rise
I try to use common transaction manager for Activiti and Hibernate, but seems Activiti reject Hibernate transaction manager.

What the problem:
1. Save variable to Activiti process
2. Rollback hibernate transaction
3. Suspend Activiti process
[Expected Result]: variable is not saved to  Activiti's DB
[Actual Result]: variable IS SAVED to Activiti's DB

What the question:
What is wrong in my configurations?
What the alternative

P.S.
All configurations I took from example - http://forums.activiti.org/comment/12292#comment-12292
My spring configurations (applicationContext) in attachment
8 REPLIES 8

trademak
Star Contributor
Star Contributor
I don't see something wrong immediately. How did you implement the transaction start, commit and rollback logic. Please share more details about your Java code.

Best regards,

jolo_
Champ on-the-rise
Champ on-the-rise
Wrong is the fact that Activiti save to DB changes that were rolled back. I implement transaction start/commit/rollback exactly as in  http://forums.activiti.org/comment/12292#comment-12292 in reply #7

Can we rollback Activiti changes without throwing exception? How?

trademak
Star Contributor
Star Contributor
It's clear that you experience issues with the rollback, but I really need more code of what you're exactly doing. There must be some problem there because rollback functionality is standard Activiti behavior and we do a lot of testing to ensure it's correct behavior.

Best regards,

jolo_
Champ on-the-rise
Champ on-the-rise
You can clone my demo from  https://github.com/JOLO-/activiti-hibernate-spring-transaction-demo.git (branch master, last commit)
To launch it you need to have PostgreSQL db
What happens in my demo:
1. I pass HibernateTransactionManager to Activiti, and use the same database for each
2. That in my service tasks (CreateClientService to be precise) I save custom entity (Client) via Hibernate & save this variable to process context (via execution.setVariable).
3. Rollback Transaction

[Result]: Client entity isn't saved to custom db, but it present in Activiti's tables

jolo_
Champ on-the-rise
Champ on-the-rise
Can you tell me why common transaction manager doesn't work in my demo?

jbarrez
Star Contributor
Star Contributor
Because of this code:

<code>
public Engine() {
        applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        hibernateSessionFactory = (SessionFactory) applicationContext.getBean("sessionFactory");
    }
</code>

You create a NEW application context. a NEW transaction manager. a NEW session factory.

And you expect this to work with the transaction manager you passed in Activiti?

binuraj_xp
Champ in-the-making
Champ in-the-making
Hi,

I just imported the source from https://github.com/JOLO-/activiti-hibernate-spring-transaction-demo and it works fine.
Then I changed the transactionmanager datasourse to cassandra. That is I have two datasources posgres and cassandra.
postgress is for activiti process engine configuration and cassandra is for my database transactions.
So I changed the configurations will be,

<bean id="cassandraDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
         <property name="driverClassName" value="org.apache.cassandra.cql.jdbc.CassandraDriver" />
         <property name="url" value="jdbc:cassandra://localhost:9160/gscp" />
    </bean>

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

I am facing some problems when configure the sessionFactory of cassandra. What will be the dialect hiberanate property for cassandra.

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" scope="singleton">
        <property name="dataSource" ref="cassandraDataSource"/>
        <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><!–org.hibernate.dialect.MySQLDialect –>
                <!–<prop key="hibernate.hbm2ddl.auto">create</prop>–>
            </props>
        </property>
    </bean>

So please help to configure the session factory for cassandra.

jbarrez
Star Contributor
Star Contributor
I'm not sure if anyone has tried that already - how compatible is Cassandra with regular SQL?

Rewriting the DbSqlSession to be cassandra compliant is quite a bit of work :s