Affects: Spring framework version 5

The Spring Reference Manual states the following.

The Spring team recommends that you annotate only concrete classes (and methods of concrete classes) with the @Transactional annotation, as opposed to annotating interfaces. You certainly can place the @Transactional annotation on an interface (or an interface method), but this works only as you would expect it to if you use interface-based proxies. The fact that Java annotations are not inherited from interfaces means that, if you use class-based proxies (proxy-target-class="true") or the weaving-based aspect (mode="aspectj"), the transaction settings are not recognized by the proxying and weaving infrastructure, and the object is not wrapped in a transactional proxy, which would be decidedly bad.

But I tried an example using CGLIB proxy, and annotate @Transactional on an interface. I expect an error. But it does not throw any error, to my surprise. I guess Spring documentation needs to be updated, maybe?

We posted our code example here in coderanch.com/forum and one staff recommends me to ask Spring community. The detail code example and discussion is here. Please take a look: https://coderanch.com/t/714204/frameworks/Spring-Transactional-inheritance

Thanks.

Comment From: sbrannen

@jhoeller, I've tentatively assigned this to you.

Comment From: DcortezMeleth

Hi. Anyone can explain why this documentation fragment is no longer relevant?

Comment From: bipster

@DcortezMeleth The documentation fragment is accurate. If you're using class-based proxies or AspectJ, the @Transactional annotation will not be processed.

I believe the original poster interpreted the last sentence (perhaps the "which would be decidedly bad" part) to mean that an error would be thrown if you use @Transactional in those contexts, which is not the case. Perhaps the documentation could be clarified by replacing:

... and the object is not wrapped in a transactional proxy, which would be decidedly bad.

with the danger spelled out:

... and the object is not wrapped in a transactional proxy. In other words, the annotations will be silently ignored and you will not realize your code does not have transactional semantics. Your code might still appear to "work" until, for example, a runtime exception in the middle of your "transaction" does not trigger a rollback.

Comment From: jhoeller

We do detect interface-annotated methods with CGLIB proxies as of #18894 now which needs to be reflected in the docs.