[jBPM] - using JTA Transactions in jBPM 3

Sascha Janz <[email protected]> Tue, 20 Aug 2013 12:14:15 -0400
Newsgroups gmane.comp.java.jboss.user
Message-ID <[email protected]>
------=_Part_620420_1086080429.1377015255274
Content-Type: multipart/alternative; 
	boundary="----=_Part_620419_746898792.1377015255273"

------=_Part_620419_746898792.1377015255273
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Sascha Janz [https://community.jboss.org/people/AJanz] created the discussi=
on

"using JTA Transactions in jBPM 3"

To view the discussion, visit: https://community.jboss.org/message/833238#8=
33238

--------------------------------------------------------------
Hello,

we are still using jBPM 3.2.3. ( seam and richfaces for frontend )=20

Due to some data inconsistencies between jBPM and our data, i wanted to use=
 JTA Transactions to get control over commit and rollback.=20

although i read the documentation i am not quite sure how to use it the rig=
ht way.=20

in jbpm.cfg.cml=C2=A0 isTransactionEnabled must still set to false, is that=
 right=C2=A0 ?=20

in hibernate.cfg.xml i change to JTA
<property name=3D"hibernate.transaction.factory_class">org.hibernate.transa=
ction.JTATransactionFactory</property>
=C2=A0 <property name=3D"hibernate.transaction.manager_lookup_class">org.hi=
bernate.transaction.JBossTransactionManagerLookup</property>
=C2=A0 <property name=3D"jta.UserTransaction">java:comp/UserTransaction</pr=
operty>

Now i want to set the commit and rollback points in our code. i wrote a sim=
ple class TransactionManager with three methods "beginTransaction" , "commi=
tTransaction" and "rollbackTransaction".

every method in our code with write access, i extended with these three met=
hods.

beginTransaction does the following

[code]
// creating new context and store in a ThreadLocal
 jbpmContextThreadLocal.set(cfg.createJbpmContext());
// on this context start a hibernate transaction=20
 Transaction=C2=A0 tx =3D jbpmContextThreadLocal.get().getSession().beginTr=
ansaction();
// and store it also in=C2=A0 a ThreadLocal
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 userTransactionThreadLocal.set(t=
x);


[/code]

commitTransaction

[code]
=C2=A0=20
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 userTransactionThrea=
dLocal.get().commit();
=C2=A0=C2=A0 userTransactionThreadLocal.remove();

=C2=A0=C2=A0=C2=A0 //=C2=A0 explizites flush!
=C2=A0=C2=A0=C2=A0 // s. unter  http://grepcode.com/file/repository.jboss.o=
rg/nexus/content/repositories/releases/org.jboss.seam/jboss-seam/2.0.0.GA/o=
rg/jboss/seam/bpm/ManagedJbpmContext.java http://grepcode.com/file/reposito=
ry.jboss.org/nexus/content/repositories/releases/org.jboss.seam/jboss-//sea=
m/2.0.0.GA/org/jboss/seam/bpm/ManagedJbpmContext.java

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 jbpmContextThreadLocal.get().getSession().flush=
();
=C2=A0=C2=A0=C2=A0 jbpmContextThreadLocal.get().close();
=C2=A0=C2=A0=C2=A0 jbpmContextThreadLocal.remove();
[/code]




 and rollback
[code]
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 userTransactionThreadLocal.get().rollback();
=C2=A0=C2=A0=C2=A0=C2=A0 userTransactionThreadLocal.remove();

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 jbpmContextThreadLocal.get().close();
=C2=A0=C2=A0=C2=A0=C2=A0 jbpmContextThreadLocal.remove();
[/code]


is this a right way to use JTA Transaction with jBPM ?=20

or am i doing something wrong?++
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/833238#833238]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=3D1&co=
ntainerType=3D14&container=3D2034]


------=_Part_620419_746898792.1377015255273
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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

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

=09=09=09=09<td>

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

=09=09=09=09=09=09=09</tr>
=09=09=09=09=09=09=09<tr>
=09=09=09=09=09=09=09=09<td bgcolor=3D"#FFFFFF" style=3D"font: normal 12px =
Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-ra=
dius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-b=
ottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style=
=3D"margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    using JTA Transactions in jBPM 3
</h3>
<span style=3D"margin-bottom: 10px;">
    created by <a href=3D"https://community.jboss.org/people/AJanz">Sascha =
Janz</a> in <i>jBPM</i> - <a href=3D"https://community.jboss.org/message/83=
3238#833238">View the full discussion</a>
</span>
<hr style=3D"margin: 20px 0; border: none; background-color: #dadada; heigh=
t: 1px;">

<div class=3D"jive-rendered-content"><p>Hello,</p><p style=3D"min-height: 8=
pt; height: 8pt; padding: 0px;">&#160;</p><p>we are still using jBPM 3.2.3.=
 ( seam and richfaces for frontend ) </p><p style=3D"min-height: 8pt; heigh=
t: 8pt; padding: 0px;">&#160;</p><p>Due to some data inconsistencies betwee=
n jBPM and our data, i wanted to use JTA Transactions to get control over c=
ommit and rollback. </p><p style=3D"min-height: 8pt; height: 8pt; padding: =
0px;">&#160;</p><p>although i read the documentation i am not quite sure ho=
w to use it the right way. </p><p style=3D"min-height: 8pt; height: 8pt; pa=
dding: 0px;">&#160;</p><p>in jbpm.cfg.cml&#160; isTransactionEnabled must s=
till set to false, is that right&#160; ? </p><p style=3D"min-height: 8pt; h=
eight: 8pt; padding: 0px;">&#160;</p><p>in hibernate.cfg.xml i change to JT=
A</p><p>&lt;property name=3D"hibernate.transaction.factory_class"&gt;org.hi=
bernate.transaction.JTATransactionFactory&lt;/property&gt;</p><p>&#160; &lt=
;property name=3D"hibernate.transaction.manager_lookup_class"&gt;org.hibern=
ate.transaction.JBossTransactionManagerLookup&lt;/property&gt;</p><p>&#160;=
 &lt;property name=3D"jta.UserTransaction"&gt;java:comp/UserTransaction&lt;=
/property&gt;</p><p style=3D"min-height: 8pt; height: 8pt; padding: 0px;">&=
#160;</p><p>Now i want to set the commit and rollback points in our code. i=
 wrote a simple class TransactionManager with three methods "beginTransacti=
on" , "commitTransaction" and "rollbackTransaction".</p><p style=3D"min-hei=
ght: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>every method in our code=
 with write access, i extended with these three methods.</p><p style=3D"min=
-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>beginTransaction doe=
s the following</p><p style=3D"min-height: 8pt; height: 8pt; padding: 0px;"=
>&#160;</p><p>[code]</p><p>// creating new context and store in a ThreadLoc=
al</p><p> jbpmContextThreadLocal.set(cfg.createJbpmContext());</p><p>// on =
this context start a hibernate transaction </p><p> Transaction&#160; tx =3D=
 jbpmContextThreadLocal.get().getSession().beginTransaction();</p><p>// and=
 store it also in&#160; a ThreadLocal</p><p>&#160;&#160;&#160;&#160;&#160;&=
#160;&#160; userTransactionThreadLocal.set(tx);</p><p style=3D"min-height: =
8pt; height: 8pt; padding: 0px;">&#160;</p><p style=3D"min-height: 8pt; hei=
ght: 8pt; padding: 0px;">&#160;</p><p>[/code]</p><p style=3D"min-height: 8p=
t; height: 8pt; padding: 0px;">&#160;</p><p>commitTransaction</p><p style=
=3D"min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>[code]</p><p>=
<span style=3D"font-size: 10pt;">&#160; </span></p><p>&#160;&#160;&#160;&#1=
60;&#160;&#160;&#160;&#160;&#160; userTransactionThreadLocal.get().commit()=
;</p><p>&#160;&#160; userTransactionThreadLocal.remove();</p><p>&#160;&#160=
; </p><p>&#160;&#160;&#160; //&#160; explizites flush!</p><p>&#160;&#160;&#=
160; // s. unter <a class=3D"jive-link-external-small" href=3D"http://grepc=
ode.com/file/repository.jboss.org/nexus/content/repositories/releases/org.j=
boss.seam/jboss-seam/2.0.0.GA/org/jboss/seam/bpm/ManagedJbpmContext.java" r=
el=3D"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>&#160;&#160;&#160; </p><p>&#160;&#160=
;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#=
160;&#160;&#160; jbpmContextThreadLocal.get().getSession().flush();</p><p>&=
#160;&#160;&#160; jbpmContextThreadLocal.get().close();</p><p>&#160;&#160;&=
#160; jbpmContextThreadLocal.remove();</p><p>[/code]</p><p style=3D"min-hei=
ght: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style=3D"min-height: 8pt=
; height: 8pt; padding: 0px;">&#160;</p><p style=3D"min-height: 8pt; height=
: 8pt; padding: 0px;">&#160;</p><p style=3D"min-height: 8pt; height: 8pt; p=
adding: 0px;">&#160;</p><p> and rollback</p><p>[code]</p><p>&#160;&#160;&#1=
60;&#160;&#160; userTransactionThreadLocal.get().rollback();</p><p>&#160;&#=
160;&#160;&#160; userTransactionThreadLocal.remove();</p><p>&#160;&#160;&#1=
60;&#160; </p><p>&#160;&#160;&#160;&#160;&#160; jbpmContextThreadLocal.get(=
).close();</p><p>&#160;&#160;&#160;&#160; jbpmContextThreadLocal.remove();<=
/p><p>[/code]</p><p style=3D"min-height: 8pt; height: 8pt; padding: 0px;">&=
#160;</p><p style=3D"min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p=
><p><span style=3D"color: #333333; font-size: 10pt;">is this a right way to=
 use JTA Transaction with jBPM ? </span></p><p style=3D"min-height: 8pt; he=
ight: 8pt; padding: 0px;">&#160;</p><p><span style=3D"color: #2a00ff; font-=
size: 10pt;"><span style=3D"color: #333333;">or am i doing something wrong?=
</span><em> </em></span></p></div>

<div style=3D"background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style=3D"margin: 0;">Reply to this message by <a href=3D"https://com=
munity.jboss.org/message/833238#833238">going to Community</a></p>
=09<p style=3D"margin: 0;">Start a new discussion in jBPM at <a href=3D"htt=
ps://community.jboss.org/choose-container!input.jspa?contentType=3D1&contai=
nerType=3D14&container=3D2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


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

</div>

</body>
</html>
------=_Part_620419_746898792.1377015255273--

------=_Part_620420_1086080429.1377015255274
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user
------=_Part_620420_1086080429.1377015255274--