I encounter following situation:
Our goal is: even if some of foo() in the loop fails, only this foo() rolls back and other successful foo()s should be committed.Code:@Transactional public void bar(){ for(int i=0; i<10; i++) { try { AnotherClass.foo(); } catch(Exception e) { // not throw further ... } } } // end ThisClass.bar(); @Transactional public void foo() { ... } // end AnotherClass.foo();
The above use will cause org.springframework.transaction.UnexpectedRollback Exception after bar() return when some foo() throws RuntimeException.
Yes, we may remove @Transactional annotation from bar() and make each foo() with a new separate transaction. But i wonder to know if it's possible to use one single transaction to fit our goal. One transaction may have better performance.
Thanks,
Herry Hong


Reply With Quote