1

In the following case,

public class Base {

    @Transactional
    public void doSave() {
       // ...
    }

 }

 public class Inherited extends Base {

     public void someMethod() {
         super.doSave();
     }

     @Override
     public void doSave() {
         super.doSave();
     }

 }

If I add the @Transactional annotation to Inherited.someMethod, the interceptor gets called without issue.

However, without the annotation on the inherited class, the interceptor does not get involved in the call to the super class from Inherited.someMethod().

Furthermore, calling Inherited.doSave() does not seem to get the interceptor invoked either. I would have expected the annotation on the superclass to be also valid on the subclass. Is this not the expected behaviour?

I am using Apache DeltaSpike for the @Transactional annotation and this is being deployed as a war in an ear (technically as a jar in a war in an ear). However, this may not be relevant as trying with a custom interceptor shows the same behaviour.

This is JBoss EAP 6.3.0 Alpha in case its relevant.

drone.ah
  • 1,135
  • 14
  • 28

1 Answers1

2

This is expected. Interceptors are only applied if the object is managed. When you you write it this way with inheritence, it's not applied as it's not part of a call stack that CDI is aware of. You would need to inject Base into your class and call Base.doSave

John Ament
  • 11,595
  • 1
  • 36
  • 45
  • Thanks. Is this also the case if the subclass overrides the method in the superclass i.e. The someMethod above is renamed to doSave? – drone.ah Aug 10 '14 at 15:37
  • Can you clarify by editing your question or posting a new question? – John Ament Aug 10 '14 at 15:54
  • That sounds like a bug to me, in EAP. According to this, we set `Transactional` to `Inherited`: https://github.com/johnament/deltaspike/blob/master/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/api/transaction/Transactional.java#L42 – John Ament Aug 11 '14 at 11:38
  • I am not sure what the accepted answer was: "not possible" or "bug in EAP" ... @John: could you update please? – Jan Galinski Aug 12 '14 at 17:28
  • @JanGalinski the EAP bug is related to the transactional interceptor only. – John Ament Aug 12 '14 at 18:49