JBoss Community

Joining JBPM transaction with my current application's transaction

created by Zeliang Huang in jBPM - View the full discussion

Hi Guys,

 

I am quite inexperienced with JTA & JPA. I am trying to join JBPM5.1 transaction with my current application's transaction.

 

In my current application, I had obtained the transaction using things like this:

building the sessionFactotry:

//my current application uses the hibernate.cfg.xml 
Configuration config = new Configuration().configure();
SessionFactory factory =  new Configuration().configure().buildSessionFactory();

 

Usering the session factory:

factory.getCurrentSession().beginTransaction();
//do CRUD
factory.getCurrentSession().commit();

 

 

In the persistence.xml of jbpm-persistence-jpa-5.1.0.Final.jar I had put

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence version="1.0"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                                 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
                                 http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
    xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="org.jbpm.persistence.jpa"
        transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>same-datasource-as-my-current-applications</jta-data-source>
        <class>org.drools.persistence.info.SessionInfo</class>
        <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
        <class>org.drools.persistence.info.WorkItemInfo</class>
        <class>org.jbpm.process.audit.ProcessInstanceLog</class>
        <class>org.jbpm.process.audit.NodeInstanceLog</class>
        <class>org.jbpm.process.audit.VariableInstanceLog</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
            <property name="hibernate.max_fetch_depth" value="3" />
        <!--     <property name="hibernate.hbm2ddl.auto" value="update" />  -->
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.transaction.manager_lookup_class"
                value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
        </properties>
    </persistence-unit>
</persistence>

 

In my JBPM StatefulKnowledgeSession creation, I had done something like this.

 

Environment env = KnowledgeBaseFactory.newEnvironment();

env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

StatefulKnowledgeSession session = JPAKnowledgeService.newStatefulKnowledgeSession(knowledgebase, null, env);

 

 

 

I am able to manage transactions of both side separately by doing something like:

//commit to my application tables first
factory.getCurrentSession().beginTransaction();
//do CRUD
factory.getCurrentSession().commit();
 
//then commit to jbpm tables. 
UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
ut.begin();
....
ut.commit();

 

This is working ok. But I prefer to combine the two transaction into one since they are supposed to be one work-unit.

 

I had trying for a week for to no avail. I am also quite confused with the fact that some hibernate apps are using hibernate.cfg.xml and some are using JPA specific persistence.xml . There are multiple copies of these XML files in different jars. I just couldn't get the whole picture of the thing. Any help is greately appreciated !

Reply to this message by going to Community

Start a new discussion in jBPM at Community