Does Spring @Transactional attribute work on a private method?

The answer your question is no – @Transactional will have no effect if used to annotate private methods. The proxy generator will ignore them.

This is documented in Spring Manual chapter 10.5.6:

Method visibility and @Transactional

When using proxies, you should apply
the @Transactional annotation only
to methods with public visibility. If
you do annotate protected, private or
package-visible methods with the
@Transactional annotation, no error
is raised, but the annotated method
does not exhibit the configured
transactional settings. Consider the
use of AspectJ (see below) if you need
to annotate non-public methods.

Leave a Comment