handle transactions externally with hibernate

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2013 10:29 AM
Hello,
I am using activiti within an existing application that uses Hibernate, with no JTA, transactions are handled "manually".
I would like to use activiti inside our own transactions so that a rollback would work at the same time on our custom code and on activiti.
I have seen the transactionsExternallyManaged parameter in ProcessEngineConfiguration, but as I understand it, it seems to be only used for JTA.
Is there any way I could pass directly my hibernate transactions (or its underlying connection) to activiti?
Thanks
I am using activiti within an existing application that uses Hibernate, with no JTA, transactions are handled "manually".
I would like to use activiti inside our own transactions so that a rollback would work at the same time on our custom code and on activiti.
I have seen the transactionsExternallyManaged parameter in ProcessEngineConfiguration, but as I understand it, it seems to be only used for JTA.
Is there any way I could pass directly my hibernate transactions (or its underlying connection) to activiti?
Thanks
Labels:
- Labels:
-
Archive
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2013 07:20 AM
If you are using Spring, it makes things easier as you can just pass the transactionmanager to the process engine configuration.
The transactionsExternallyManaged is actually used to determine which transaction factory is used in Ibatis. So my guess it would work, however, I haven't tested it yet with Hibernate alone.
The transactionsExternallyManaged is actually used to determine which transaction factory is used in Ibatis. So my guess it would work, however, I haven't tested it yet with Hibernate alone.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2013 03:40 AM
The problem is, we don't use Spring. We don't have a TransactionManager, we directly use the hibernate session. That's why I was wondering if we could pass directly the java.sql.Connection to activiti…
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2013 04:16 AM
Activiti uses a datasource for fetching SQL-connections. If you have a datasource (or proxy) that is aware of the hibernate-transaction and always returns the SQL-connection active in the hibernate-context, this can work perfectly, in combination with the "transactions managed externally".
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2013 01:04 PM
I've tried and achieved sometinhg similar, but can't and won't share the code… Why: if you want integration of frameworks, use the existing solutions for that, a transactionmanager. Waaaaay reasier, portable etc…

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2013 04:14 AM
In fact just using a custom datasource wasn't enough.
The solution that worked for us :
- create a Datasource that always gives the connection of our current hibernate session
- create an engine configuration that overrides initDataSource and initDatabaseType
- set transactionExternallyManaged to true
- create our own TransactionContext that does neither commit nor rollback (but tells our system that the transaction is not committable when the method rollback is called)
- add "closeConnection" = "false" to the properties of the transaction factory
Hope this helps if someone else has the same need…
The solution that worked for us :
- create a Datasource that always gives the connection of our current hibernate session
- create an engine configuration that overrides initDataSource and initDatabaseType
- set transactionExternallyManaged to true
- create our own TransactionContext that does neither commit nor rollback (but tells our system that the transaction is not committable when the method rollback is called)
- add "closeConnection" = "false" to the properties of the transaction factory
Hope this helps if someone else has the same need…
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2013 03:16 PM
Cool isn't it, these details… Soooo much simpeler than just using a JEE server with a normal TM

