0

Example:

class Example {
@Inject
Bee b; // proxy
public void exec() {
 b.exec();
}

class Bee {
  public void exec() {
  exec2();
 }
 @Transactional
 public void exec2() {}
}

As I recently noticed, this will not work. Am I right? Do you have some links to documentation that states that behavior? IMO this case could be handled in the future because intuitively it seems that it should work.

Matt
  • 35
  • 8
  • 1
    Does this answer your question? [Spring @Transaction method call by the method within the same class, does not work?](https://stackoverflow.com/questions/3423972/spring-transaction-method-call-by-the-method-within-the-same-class-does-not-wo) – Savior Nov 25 '20 at 15:31
  • 1
    Due to the default use of proxies this won't work, you would need to inject `Bee` into `Bee` and do self invocation (so that it passes through the proxy again). This issue dates back to the time of EJB1.0 (and probably before that in Project San Fransisco) and has to do with the nature of proxies. – M. Deinum Nov 25 '20 at 15:36

1 Answers1

1

The relevant section of the CDI specification is section 7.2 (Container invocations and interception). Since exec2() is not invoked via a contextual reference, its invocation does not constitute a business method invocation. Since it is not a business method invocation, interceptors responsible for implementing the behavior prescribed by @Transactional are not invoked.

Laird Nelson
  • 15,321
  • 19
  • 73
  • 127