aspose file tools*
The moose likes Spring and the fly likes Confusion related to @Transactional annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Confusion related to @Transactional annotation" Watch "Confusion related to @Transactional annotation" New topic
Author

Confusion related to @Transactional annotation

Maneeesh Saxena
Greenhorn

Joined: Dec 24, 2006
Posts: 26

hi Great Ranchers,


Please refer the below code.






In class shown above insertUser() makes a call to deleteUser(). As per my understanding deleteUser() should have been executed in a new/saparate transaction, as it's annotated as @Transactional(propagation = Propagation.REQUIRES_NEW), but it's not happening that way. Instead deleteUser() is also executing in same transaction as that of insertUser(). Below is the log for this code which shows the same.



If that's correct than what is the use of @Transactional(propagation = Propagation.REQUIRES_NEW) annotation at deleteUser().

How a method will execute in saparate transaction if it's marked with an annotation @Transactional(propagation = Propagation.REQUIRES_NEW).

I am confused, please help me. Please let me know if question is not clear.


Best Regards,
Maneesh Saxena
Maneeesh Saxena
Greenhorn

Joined: Dec 24, 2006
Posts: 26
complete log in case it's needed.

Maneeesh Saxena
Greenhorn

Joined: Dec 24, 2006
Posts: 26
Any One .. Any Help !!!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Transactions are added via a Proxy. But if one method inside your dao calls another method inside your dao. The call does not go back outside the class to call through the proxy again. So therefore, the second method is called directly from the first method and no Transaction code will be wrapped around the second method.

So imagine you go into a house, and at the door you get something handed to you. You are in the hallway now and you go to the kitchen. To get to the kitchen, you don't go through the front door again, you go directly to the kitchen.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Maneeesh Saxena
Greenhorn

Joined: Dec 24, 2006
Posts: 26
Thanks Mr. Mark. I got it. Thanks for such a nice explanation.

Best Regards,
Maneesh Saxena
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Maneeesh Saxena wrote:Thanks Mr. Mark. I got it. Thanks for such a nice explanation.

Best Regards,
Maneesh Saxena


Thank you. I made up that analogy on the fly as I was typing. But I really do like it.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confusion related to @Transactional annotation