Announcement Announcement Module
Collapse
No announcement yet.
Can we use one single transaction to commit successful actions without failure ones? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can we use one single transaction to commit successful actions without failure ones?

    I encounter following situation:
    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();
    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.

    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
    Last edited by honzeland; Feb 28th, 2010, 10:19 PM.

  • #2
    No one responses? Let me reply it myself.~~

    Comment

    Working...
    X