<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Separating JBPM 5.1 Process persistence from workitemhandler business logic transaction
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/lakshmi.sampath">lakshmi sampath</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/724547#724547">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I am persisting the knowledge session using JPA/JTA and I need to separate jbpm process related persistence from business logic persistence so that when I use asynchronous service work item handlers to call the business logic<br/> and if the business logic fails and rollbacks a transaction, I still want the process related information, history log and mainly the asynchronous work item to be persisted.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here's the exception thrown when JBPM tries to commit the asynchnous work item after the business logic called inside a workitem rollbacks a transaction.</p><ol><li>How do I make sure that JBPM uses a separate transaction always and not share it with the business logic transaction.</li><li>Even if JBPM uses separate transaction, does it also rollback if business logic transaction rollbacks since they are part of same JTA User Transaction(Which I dont want JBPM to do).</li></ol><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Note: Both JBPM persistence and business logic share the same database and datasource.</p><p>&#160;&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>2012-03-17 17:30:31,032 WARN [org.drools.persistence.jta.JtaTransactionManager] Unable to commit transaction</p><p>javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state</p><p> at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1394)</p><p> at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)</p><p> at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)</p><p> at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)</p><p> at org.drools.persistence.jta.JtaTransactionManager.commit(JtaTransactionManager.java:167)</p><p> at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:294)</p><p> at org.drools.command.impl.CommandBasedStatefulKnowledgeSession.startProcessInstance(CommandBasedStatefulKnowledgeSession.java:237)</p><p> at com.hp.adam.processengine.impl.JBPMProcessEngine.startProcess(JBPMProcessEngine.java:35)</p><p>...</p><p>Caused by: java.lang.IllegalStateException: BaseTransaction.rollback - [com.arjuna.ats.internal.jta.transaction.arjunacore.notx] [com.arjuna.ats.internal.jta.transaction.arjunacore.notx] no transaction!</p><p> at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.rollback(BaseTransaction.java:158)</p><p> at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.rollback(BaseTransactionManagerDelegate.java:126)</p><p> at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.rollback(ServerVMClientUserTransaction.java:148)</p><p> at org.drools.persistence.jta.JtaTransactionManager.rollback(JtaTransactionManager.java:183)</p><p> ... 21 more</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here's how I am configuring and starting the process. Note that I autowire spring to retrieve transaction manager, <br/>primarily to get hold of UserTransaction object instead of lookup from JNDI. </p><p>---------------------------------------------------------------------------------------------------------------------------------------------------------</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>@Autowired</strong></p><p><strong>org.springframework.transaction.jta.JtaTransactionManager txm;</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();</p><p>kbase=kbuilder.newKnowledgeBase();</p><p>kbuilder.add(ResourceFactory.newClassPathResource("bpmn2Process.bpmn"), ResourceType.BPMN2);</p><p>&#160;&#160;&#160; </p><p>EntityManagerFactory emf =&#160; Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");</p><p>Environment env = KnowledgeBaseFactory.newEnvironment();</p><p>env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );</p><p>env.set(EnvironmentName.TRANSACTION, <span style="text-decoration: underline;"><strong>txm.getUserTransaction()</strong></span>);</p><p>&#160;&#160;&#160; </p><p>StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase,null,env);</p><p>ksession.getWorkItemManager().registerWorkItemHandler("ServiceWorkItem", (WorkItemHandler)object); </p><p>JPAWorkingMemoryDbLogger processDbLogger = new JPAWorkingMemoryDbLogger(ksession);</p><p>-----------------------------------------------------------------------------------------------------------------------------------------------------------</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Also attached the persistence.xml file</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>thanks</p><p>lakshmi.</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/724547#724547">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>