<!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">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;">
    achieving sub transaction
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/techy_kans">Kannan S</a> in <i>EJB 3.0 Development</i> - <a href="http://community.jboss.org/message/567017#567017">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 all</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>We have a unique problem in our application. We have got five to six EAR files out of which two ear files interact with the database and one EAR file is a MDB listener. Lets say one of our db interacting EAR files, which is ejb module, is, Business.EAR The following is the main way the business is implemented.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The bean name is BusinessProcessorBean.java for which we have interceptor called PreProcessingInterceptor. The following is the code in PreProcessingInterceptor.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> PreProcessingInterceptor<font color="navy">{</font>
@AroundInvoke
<font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> doPreProcessing()<font color="navy">{</font>
 <font color="navy"><b>try</b></font><font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160; 1. <font color="navy"><b>do</b></font> some db operations
&#160;&#160;&#160;&#160;&#160;&#160; 2. InvocationContext.proceed() -&#160; call the bean
<font color="navy">}</font><font color="navy"><b>catch</b></font>(Exception exp)<font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(<font color="red">"Exception "</font>+exp);
<font color="navy">}</font><font color="navy"><b>finally</b></font><font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160; PostProcessingInterceptor ppi = <font color="navy"><b>new</b></font> PostProcessingInterceptor();
&#160;&#160;&#160;&#160;&#160;&#160; 3.ppi.doPostProcessing();
<font color="navy">}</font>
<font color="navy">}</font>
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Now we have got a problem in which there may be an exception at the end of point 1 or at the end of point 3. We want to have atleast half transaction in DB so that we can get some data from the database. I came to know that we can do nested transaction . Our bean is container managed. How do i change it to bean manage so that i can re write the java code some thing like</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive_text_macro jive_macro_code"><p>public class PreProcessingInterceptor{</p><p>@AroundInvoke</p><p>public void doPreProcessing(){</p><p> try{</p><p>&#160;&#160;&#160;&#160;&#160;&#160; a. transaction.begin();&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160; 1. do some db operations</p><p>&#160;&#160;&#160;&#160;&#160;&#160; b. transaction.commit();&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160; 2. InvocationContext.proceed() -&#160; call the bean</p><p>}catch(Exception exp){</p><p>&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Exception "+exp);</p><p>}finally{</p><p>&#160;&#160;&#160;&#160;&#160;&#160; PostProcessingInterceptor ppi = new PostProcessingInterceptor();</p><p>&#160;&#160;&#160;&#160;&#160;&#160; c. transaction.begin();&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160; 3.ppi.doPostProcessing();</p><p>&#160;&#160;&#160;&#160;&#160;&#160; d. transaction.commit();</p><p>}</p><p>}</p><p>}</p></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Please guide me so that our application saves data atleast in a few tables rather than not updating any tables.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Regards</p><p>Kannan.S</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/567017#567017">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB 3.0 Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2030">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


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

</div>

</body>
</html>