Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring Transaction management
    text
    copied!<p>In java Spring, I am facing an issue regarding transaction rollback. </p> <p>Example:</p> <p>I have 3 DAOs in my code (A, B, C). All of them extend <code>JDBCTemplate</code>:</p> <pre><code>@Transaction(propagation=new_required) public void serviceClassProc() throws Exception { A.db1(); B.db2(); C.db3(); } </code></pre> <p>Now with the above code if I throw an exception in <code>B.db2()</code>, nothing gets rolled back.</p> <p>Now if I modify <code>B.db2</code> as following:</p> <pre><code>@Transaction(propagation=nested,rollbackon=Exception.class) public void db2() throws Exception{ ... throw new Exception(); } </code></pre> <p>And then call <code>serviceClassProc()</code>, only the transaction in <code>B.db2</code>, gets rolled back.</p> <p>I want an implementation where all transactions inside <code>serviceClassProc()</code> get rolled back. </p> <p>Here are the 2 configurations I am using:</p> <pre><code>&lt;bean id="bonddao" class="com.marki.bonds.staticdata.dao.MuniStaticDataDaoImpl"&gt; &lt;property name="dataSource" ref="c3p0DataSource" /&gt; &lt;/bean&gt; &lt;bean id="dcldao" class="com.bonds.staticdata.dao.DclSettingsDaoImpl"&gt; &lt;constructor-arg ref="c3p0DataSource" /&gt; &lt;/bean&gt; &lt;bean id="batchlogdao" class="com.bonds.staticdata.dao.MuniFeedHandlerBatchLogDaoImpl"&gt; &lt;constructor-arg ref="c3p0DataSource" /&gt; &lt;/bean&gt; &lt;bean id="bondsApplication" class="com.markit.bonds.staticdata.service.MuniRefDataSyncApp"&gt; &lt;property name="refdataService" ref="refDataSynchService" /&gt; &lt;property name="mailService" ref="mailSender"&gt;&lt;/property&gt; &lt;property name="batchLogger" ref="batchlogdao"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt; &lt;property name="dataSource" ref="c3p0DataSource" /&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt; </code></pre> <p>Where I am going wrong? Is it wrong to have 3 DAOs all extending JDBC template? Should all of them share same JDBCTemplate?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload