wood burning stoves 2.0*
The moose likes Spring and the fly likes Understanding Propagation Required and Nested scnearios Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Understanding Propagation Required and Nested scnearios" Watch "Understanding Propagation Required and Nested scnearios" New topic
Author

Understanding Propagation Required and Nested scnearios

scott miles
Ranch Hand

Joined: Jun 16, 2011
Posts: 70
I went through http://static.springsource.org/sprin...tx-propagation But got bit confused. So though of clearing the understanding with below scenarios. Please let me know if below understanding is correct?

Class MyClass1{

//Propagation is Propagation required
public void method1();
{

method1A();
method1B();
MyClass2 myClass2= getBean("MyClass");
myClass2.method2A();
myClass2.method2B();
}


// No porapgation is defined here so default will be reuired
public method1A()
{
//Some Transaction
}


// No porapgation is defined here so default will be reuired
private method1B()
{
//Some Transaction
}

}



Class MyClass2{

//Propagation is Propagation required
public void method2();
{

method2A();
method2B();
}


// No porapgation is defined here so default will be required
public method2A()
{
//Some Transaction
}


// No porapgation is defined here so default will be required
public method2B()
{
//Some Transaction
}

}


Now here are the scenarios

we call the method1() of MyClass1 inside main method



Scenarion1:-

No exception occurs. transaction will be created before method1A() and will be commited after myClass2.method2B(); Right?



Scenarion2:-

Runtime exception occurs during method1B. Complete transaction will be rolled back. Right?




Scenarion3:-

Runtime exception occurs during method2A(Transaction under method2A will be treated as part of transaction created
under method1 in class1) .Complete transaction will be rolled back. Right?



Scenarion4:-

Runtime exception occurs during method2B(Transaction under method2A will be treated as part of transaction created
under method1 in class1) .Complete transaction will be rolled back. Right?

-------------------------------------------------------------------------------------------------------


Now if we consider the same scenarios with propagation as Nested for methods method2A and method2B.



Scenarion1:-

No exception occurs. transaction will be created on entering method1A() and will be commited on exit of method1A().Right?



Scenarion2:-

Runtime exception occurs during method1B. Complete transaction will be rolled back.Right?


Scenarion3:-

Runtime exception occurs during method2A .Only transaction under method2A will be rolled back and rest of the transaction will be commited
on exit of method1.Right?



Scenarion4:-

Runtime exception occurs during method2B. Only transaction under method2B will be rolled back and rest of the transaction will be commited
on exit of method1.Right?

Posted at http://forum.springsource.org/showthread.php?113272-Understanding-Propagation-Required-and-Nested-scnearios&p=376001#post376001. But did not get replies as of now.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

OK lets do this another way.

A calls B
A might have started a transaction or it might not have. But B is set to be Transactional with a Propagation setting. What happens to A's transaction or lack there of, when B is called.




In both cases B will be running in a transaction. Either a new transaction in 3/4 scenarios or in 1 scenario just join A's transaction.

Also, in order to use NESTED, your Jdbc Driver must supports JDBC's save points. Otherwise NESTED will work exactly like REQUIRES_NEW

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
scott miles
Ranch Hand

Joined: Jun 16, 2011
Posts: 70
Thanks Mark For reply.Got your point. But it would be a great help if you can just reply the original post different scenario in yes/no to get the better clarity. sorry for inconvenience.Actually looking for it Long time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Understanding Propagation Required and Nested scnearios
 
Similar Threads
Problem inserting to Database
Clarification on Propagation Nested in spring
RemoteException after EJB call
how does rollbackFor work ?
Stateful Session Bean Discard