Version 2

    Setting up jBPM 3.2 to use Container Managed Transactions (CMT) inside JBoss AS needs some configuration changes.


    Note: The enterprise archive is properly configured and can always be taken as a reference. The configuration files can be found in jbpm-jpdl-3.2.GA/deploy/jbpm-enterprise.ear/lib/jbpm-configs.jar; the files to look at are:


    • jbpm.cfg.xml

    • hibernate.cfg.xml


    The relevant snippets of these configuration files are posted here for your convenience:




        <service name="persistence" factory="org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory" ></service>
        <service name="message" factory="org.jbpm.msg.jms.JmsMessageServiceFactoryImpl" ></service>
        <service name="scheduler" factory="org.jbpm.scheduler.ejbtimer.EjbSchedulerServiceFactory" ></service>
        <service name="tx" factory="org.jbpm.tx.TxServiceFactory" ></service>
        <service name="logging" factory="org.jbpm.logging.db.DbLoggingServiceFactory" ></service>
        <service name="authentication" factory="" ></service>


    The relevant setting is the one for the persistence service factory org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory.




        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
        <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>


    Again, make sure to set this configuration to use the org.hibernate.transaction.JTATransactionFactory. When JTATransactionFactory is configured, Hibenate will use the JTA transaction if it already exists, but will start a JTA transaction if it does not.





    Using the same Hibernate session for your custom beans



    If you have application data that has to be persisted via Hibernate or EJB3 entity beans, you can set up jBPM to share a "global" session with the application data. Just create a persistence.xml and then inject it into your SLSB and set it on the jbpmContext via jbpmContext.setSession(s). All of the updates / inserts on the same thread will commit or rollback together, at least with many database management systems (e.g. Oracle, MySql, etc.), which is a very convenient way to get "global" transaction without using XA (Note: this assumes your jBPM tables are in the same schema as your other data or one schema can be referenced from the other).