I’ve got in my project code similar to this
@Transactional(readOnly = true)
public void tt() {
dd();
}
@Transactional()
public void dd() {
gg();
}
@Transactional(readOnly = true)
public void gg() {
}
Function dd is used both by other readonly transaction functions and not readonly functions. Assuming that transaction should extendend from execution of tt to gg – operations in dd will in be read-only transaction or not?
Spring’s
AbstractPlatformTransactionManagerhas a property namedvalidateExistingTransactionthat controls this behavior. Javadoc states that:Since default propagation for Spring
@Transactionalannotation isREQUIREDand default validation strategy is false, I expect Spring to use existing transaction created fromttmethod call in readonly mode.If you want to have a read only transaction, then you have to annotate your method with: