cancel
Showing results for 
Search instead for 
Did you mean: 

Transactions in Java Service Tasks

oticman
Champ in-the-making
Champ in-the-making
Hi all,
I'm going to use for the first time Activiti in a new document management project, so I would like to understand what are the 'best practice' to set up an application like this one.
I want to keep this application really lightweight, so I will use only a servlet container (like tomcat), jpa1 for persistence and I would prefer to avoid Spring, because the developing team is not skilled in it.
Activiti is really wonderful framework and I'll use it in the future, probably also when there will not be a real 'bpm requirement', because it is useful to 'organize' the whole application.
So, I would like to understand some points :

1) Is it possible to use Activiti in a plain java web application ? (No EJB, No Spring, Only Local Transactions)
2) Is it mandatory to use JTA or XA transactions ?

If it's possible to use simple local transactions, then I would like to understand how can I share with Activiti the same db connection (or EntityManager in JPA) to use it in all custom java code, such as JavaDelegate classes. I think that sharing connection is the only way to maintain a good transactional consistency between Activiti db operations and JavaDelegate custom db operations ? Isn't it ? 

I think it would be a great help if someone added to wiki or to user guide some scenarios of 'real world' usage, with persistence actions within java service tasks or java listeners.


Thank you very much for the awesome work !

Ottavio
3 REPLIES 3

trademak
Star Contributor
Star Contributor
Hi,

1. Sure you can use Activiti without needing a Spring configuration, EJBs and only local transactions
2. No, you only need JTA or XA transactions when your requirements are so.

If you want to use JPA to access your own database entities you don't need JTA or XA transactions as well. You may however have requirements that force you to use JTA or XA transactions.
If you use JPA with local transactions, it can occur that a database entity is updated in a process instance that's rollbacked for some reason. The database entity was already committed if you use local transactions and not rolled back. For more information you can look at the user guide. And in addition, in my Activiti in Action book there's a section about using JPA with Activiti.

Best regards,

meyerd
Champ on-the-rise
Champ on-the-rise
Hi oticman,

Activiti does integrate with JTA, Spring and plain JDBC transactions.

You can configure actviti to use plain JDBC transaction using the StandaloneProcessEngineConfiguration.

If you want to share plain JDBC transactions between you JPA EntityManager and Activiti you have to make sure both do work in the same JDBC Connection and write some kind of abstraction for commit / rollback synchronizations. If you do not want to do that yourself, you can use the Springframework which already provides everything you need. You can use Spring just to solve this problem, without using it as a programming model for the application.

oticman
Champ in-the-making
Champ in-the-making
Thanks meyerd, I will follow your advice.