Thursday 25 March 2021

@Transaction management internals (Proxy pattern)

How exactly @Transaction works:

Earlier we used to start, close, rollback the transactions programmatically. But with the introduction of @Transaction annotation life became easy. All the underlying transaction management will he handled by the framework.

@Service

public class EmployeeService {

        @Transactional

    public void saveEmployee (Employee employee){

        dao.saveEmployee (employee);

    }

}

The underlying  transaction managers handle the transaction, whichever is used, for example: HibernateTransactionManager or JpaTransactionManager


Internally Spring creates a Proxy for the EmloyeeService class. This proxy class is the one which handles the transaction management related activates, including exception handling and rollback of the transaction








No comments:

Post a Comment