Results 1 to 2 of 2

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

  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Default 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 at 10:19 PM.

  2. #2
    Join Date
    Feb 2010
    Posts
    2

    Default

    No one responses? Let me reply it myself.~~

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •