[jboss-user] [jBPM] - Joining JBPM transaction with my current application's transaction

Zeliang Huang do-not-reply at jboss.com
Sun Dec 11 22:35:29 EST 2011


Zeliang Huang [http://community.jboss.org/people/ossa] created the discussion

"Joining JBPM transaction with my current application's transaction"

To view the discussion, visit: http://community.jboss.org/message/640954#640954

--------------------------------------------------------------
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
[http://community.jboss.org/message/640954#640954]

Start a new discussion in jBPM at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20111211/06822537/attachment.html 


More information about the jboss-user mailing list