user2740224
user2740224

Reputation:

@Transactional on class definition and on all methods. What are the differences?

What are the differences?:

  1. marked class @Transactional
  2. marked all methods of this class @Transactional

Thanks.

Upvotes: 2

Views: 908

Answers (2)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136082

The only difference is that @Transactional is an inherited annotation (at least if we are talking about Spring) so @Transactional on a class definition will be inherited by subclasses while @Transactional on methods will not be inherited by overriding methods

Upvotes: 2

David
David

Reputation: 20073

Marking @Transactional on all methods is the same as making the class @Transactional.

However, say you only had 3 out of 6 methods in your class that needed to be marked transactional you should only mark those three.

Transactional Annotations should be placed around all operations that are inseparable so you also gain abilities to do things like rollback if required within one transaction.

Upvotes: 2

Related Questions