<!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="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">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;">
    How to provide my own transaction to jBPM?
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/helmers">Guido Helmers</a> in <i>jBPM Development</i> - <a href="http://community.jboss.org/message/536887#536887">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>we're using jBPM 4.3, the jBPM tables are part of a bigger database schema, also containing our own tables.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Our transactional service method looks like this:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @Transactional</p><p>&#160;&#160;&#160; public String create(Issue issue) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // <a class="" href="http://community.jboss.org/message/536887#536887/1">http://community.jboss.org/message/536887#536887/1</a> (own stuff)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; issueDao.persist(issue);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Map&amp;lt;String, Object&amp;gt; variables = new HashMap&amp;lt;String, Object&amp;gt;();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; variables.put("ISSUE_ID", issue.getId());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // <a class="" href="http://community.jboss.org/message/536887#536887/2">http://community.jboss.org/message/536887#536887/2</a> (jBPM stuff)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ProcessInstance processInstance = executionService.startProcessInstanceByKey("PROCESS_KEY", variables);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // <a class="" href="http://community.jboss.org/message/536887#536887/3">http://community.jboss.org/message/536887#536887/3</a> (jBPM stuff)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; List list = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // ... etc</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>First we write some stuff to our own tables, then we tell jBPM to start a process. This is all done within one transactional method (I was hoping...).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>jbpm.cfg.xml:</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>tx.hibernate.cfg.xml:</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>The problem...</strong></p><p>The problem is that jBPM creates its own transaction, and does not take part in the transaction started by our own application (as you can see by writing an integration test that succeeds on steps [1] and [2], but uses a mockTaskService to throw an exception at [3] - what you see then is that our own tables are emptied (top-level transaction is rolled-back), but JBPM4_HIST_PROCINST is still filled, in other words [2] is executed in its own transaction and is not rolled back).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I tried to remove the "standard-transaction-interceptor" from tx.hibernate.cfg.xml hoping that jBPM would magically participate in my own transaction, but that doesn't make jBPM very happy.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Does anyone have an idea how I can tell jBPM to use my transaction, instead of starting its own?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I read in the jBPM 4 developer's guide:</p><p><a class="jive-link-external-small" href="http://docs.jboss.org/jbpm/v4/devguide/html_single/#d0e2216">http://docs.jboss.org/jbpm/v4/devguide/html_single/#d0e2216</a></p><p>that <em>"User provided transasctional resources such as JDBC connections or hibernate connections"</em> is not yet available in jBPM4. I guess this feature is what I need... is it already implemented or in the pipeline? Does anyone know when this feature will be available, or if there is a workaround for it?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>This post is related to my earlier post on the fact that jbpm4 does not use the hibernate SessionFactory injected into it:</p><p><a class="jive-link-external-small" href="https://community.jboss.org/thread/150549?tstart=0">https://community.jboss.org/thread/150549?tstart=0</a></p><p>In the test project attached to that issue, you can also see how transaction management in our application works... Perhaps the problem is solved as soon as the SessionFactory injection issue is solved?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Cheers,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Guido</p></div>

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


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

</div>

</body>
</html>