<!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;">
using JTA Transactions in jBPM 3
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/AJanz">Sascha Janz</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/833238#833238">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hello,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>we are still using jBPM 3.2.3. ( seam and richfaces for frontend ) </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Due to some data inconsistencies between jBPM and our data, i wanted to use JTA Transactions to get control over commit and rollback. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>although i read the documentation i am not quite sure how to use it the right way. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>in jbpm.cfg.cml  isTransactionEnabled must still set to false, is that right  ? </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>in hibernate.cfg.xml i change to JTA</p><p><property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property></p><p>  <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property></p><p>  <property name="jta.UserTransaction">java:comp/UserTransaction</property></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Now i want to set the commit and rollback points in our code. i wrote a simple class TransactionManager with three methods "beginTransaction" , "commitTransaction" and "rollbackTransaction".</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>every method in our code with write access, i extended with these three methods.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>beginTransaction does the following</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>[code]</p><p>// creating new context and store in a ThreadLocal</p><p> jbpmContextThreadLocal.set(cfg.createJbpmContext());</p><p>// on this context start a hibernate transaction </p><p> Transaction  tx = jbpmContextThreadLocal.get().getSession().beginTransaction();</p><p>// and store it also in  a ThreadLocal</p><p>        userTransactionThreadLocal.set(tx);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>[/code]</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>commitTransaction</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>[code]</p><p><span style="font-size: 10pt;">  </span></p><p>          userTransactionThreadLocal.get().commit();</p><p>   userTransactionThreadLocal.remove();</p><p>   </p><p>    //  explizites flush!</p><p>    // s. unter <a class="jive-link-external-small" href="http://grepcode.com/file/repository.jboss.org/nexus/content/repositories/releases/org.jboss.seam/jboss-seam/2.0.0.GA/org/jboss/seam/bpm/ManagedJbpmContext.java" rel="nofollow">http://grepcode.com/file/repository.jboss.org/nexus/content/repositories/releases/org.jboss.seam/jboss-//seam/2.0.0.GA/org/jboss/seam/bpm/ManagedJbpmContext.java</a></p><p>    </p><p>                  jbpmContextThreadLocal.get().getSession().flush();</p><p>    jbpmContextThreadLocal.get().close();</p><p>    jbpmContextThreadLocal.remove();</p><p>[/code]</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p> and rollback</p><p>[code]</p><p>      userTransactionThreadLocal.get().rollback();</p><p>     userTransactionThreadLocal.remove();</p><p>     </p><p>      jbpmContextThreadLocal.get().close();</p><p>     jbpmContextThreadLocal.remove();</p><p>[/code]</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="color: #333333; font-size: 10pt;">is this a right way to use JTA Transaction with jBPM ? </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="color: #2a00ff; font-size: 10pt;"><span style="color: #333333;">or am i doing something wrong?</span><em> </em></span></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/833238#833238">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>