Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confusion related to @Transactional annotation

 
Maneeesh Saxena
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
complete log in case it's needed.

 
Maneeesh Saxena
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any One .. Any Help !!!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Maneeesh Saxena
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mr. Mark. I got it. Thanks for such a nice explanation.

Best Regards,
Maneesh Saxena
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic