13.4. Implementing Container Managed Transaction

You can embed JBoss BPM Suite inside an application that executes in Container Managed Transaction (CMT) mode, such as Enterprise Java Beans (EJB).
To configure the transaction manager, follow these steps:
  1. Implement the dedicated transaction manager:
    org.jbpm.persistence.jta.ContainerManagedTransactionManager
  2. Insert the transaction manager and persistence context manager into the environment before you create or load your session:
    Environment env = EnvironmentFactory.newEnvironment();
    env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
    env.set(EnvironmentName.TRANSACTION_MANAGER, new ContainerManagedTransactionManager());
    env.set(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, new JpaProcessPersistenceContextManager(env));
    env.set(EnvironmentName.TASK_PERSISTENCE_CONTEXT_MANAGER, new JPATaskPersistenceContextManager(env));
  3. Configure JPA provider (example hibernate and WebSphere):
    <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory"/>
    <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.WebSphereJtaPlatform"/>

Note

To ensure that the container is aware of process instance execution exceptions, ensure that exceptions thrown by the engine are sent to the container to properly reverse the transaction.
Using the CMT Dispose Ksession Command

If you dispose of your Ksession directly when running in the CMT mode, you may generate exceptions, because JBoss BPM Suite requires transaction synchronization. Use org.jbpm.persistence.jta.ContainerManagedTransactionDisposeCommand to dispose of your session.