Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I added comment to Spring <a href="https://jira.springsource.org/browse/SPR-6908" rel="nofollow">improvement ticket</a> on this. I'll copy it here too:</p> <p>I worked around this problem by converting all service methods that were declaratively setup like this</p> <pre><code>@Transactional(propagation = REQUIRES_NEW) public Object doSmth() { // doSmthThatRequiresNewTx } </code></pre> <p>to use <code>TransactionTemplate</code> instead:</p> <pre><code>private TransactionTemplate transactionTemplate; public Object doSmth() { return transactionTemplate.execute(new TransactionCallback&lt;Object&gt;() { @Override public Object doInTransaction(TransactionStatus status) { // doSmthThatRequiresNewTx } }); } </code></pre> <p>Under tests I configure <code>transactionTemplate</code>'s propagation behavior to be <code>PROPAGATION_REQUIRED</code>, under real app I configure <code>transactionTemplate</code>'s propagation behaviour to be <code>PROPAGATION_REQUIRES_NEW</code>. It works as expected. The limitation of this workaround is that under tests it is not possible to assert the fact that inner transaction is <strong>not</strong> rolledback in an exceptional scenario.</p> <p>The other solution would be to explicitly delete everything <code>doSmth()</code> does in the database in the <code>@AfterTransaction</code> method in test. That 'delete' SQL will be run in the new transaction, as its results would be otherwise rolled back routinely by Spring's <code>TransactionConfiguration</code> default behaviour.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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