AnsweredAssumed Answered

Persistence

Question asked by tizo on Jan 24, 2011
Latest reply on Jan 26, 2011 by ronald.van.kuijk
We have had some problems with persistence in Activiti. First I will describe the environment where we are using it.

Activiti is used in an EJB, which is deployed in a GlassFish server. Spring is not used. The engine is created when an instance of the EJB is created (in a method annotated with @PostConstruct); I know that probably this is a bad decision for the performance, but after finding a solution for the problem of persistence, we will try to start the Activiti engine as a GlassFish service, and obtain it with jndi.

The EJB is using JTA with CMT and JPA. Activiti on the other hand, is using it owns persistence layer, with the JDBC properties configured in activiti.cfg.xml.

The big problem that we are having, is that Activiti transactions are totally independent from the container transactions. So there are times when the container transaction is rolled back due to an error, but the Activiti transaction is happily committed.

Having all the picture in mind, I think that the two possibles solutions for our problem are (in that order):

- Making Activiti use the same Entity Manager that is used by the EJB, as it is configured with JTA. I have seen that in Activiti 5.1 User Guide, there is an example on how to use JPA. However, I think that this example is useful when JPA entities need to be handled, but not for the persistence of Activiti tables: I have tried it, and it keep asking me for org.h2.Driver. I think that if JPA was used for the entities and Activiti tables, the engine should not worry about JDBC connection, as all that it would need was the Entity Manager.

- Making Activiti use a DataSource obtained from the container (with @Resource annotation). I have tried updating a DB A with an EntityManager, and a DB B with a DataSource, and both modifications are done in the same transaction, using XA to commit them. It is important to note again that Spring is not used in our environment, and I don't know if Activiti can be configured with a DataSource from the container (without Spring).

Any suggestion?

Thanks very much.

Outcomes