Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why must methods annotated with @Transactional be overrideable

I have the following code:

/**
 * Restored deleted partner
 */
@Transactional
public void restorePartnerById(Integer id){
    // logic      
}

When I make the method final

/**
 * Restored deleted partner
 */
@Transactional
public final void restorePartnerById(Integer id){
    // logic      
}

I get a compilation error stating:

Methods annotated with @Transactional must be overridable

I went digging around but I cannot get the reason why it must be override able, Why must the method be override able?

like image 608
Christiaan Avatar asked Oct 09 '18 07:10

Christiaan


2 Answers

Spring's Transactional works with creating a proxy class that override methods:

create a transactional proxy around the object that is created from the fooService bean definition. The proxy will be configured with the transactional advice, so that when an appropriate method is invoked on the proxy

like image 111
user7294900 Avatar answered Sep 20 '22 16:09

user7294900


I think changing a method to final is not relevant to @Trasacational ,see this link how the @Trasactional will work http://www.codingpedia.org/jhadesdev/how-does-spring-transactional-really-work/

like image 28
Mahender Ambala Avatar answered Sep 21 '22 16:09

Mahender Ambala