@Transactional inheritance [SPR-7180] #11839
Labels
in: data
Issues in data modules (jdbc, orm, oxm, tx)
status: bulk-closed
An outdated, unresolved issue that's closed in bulk as part of a cleaning process
David Cole opened SPR-7180 and commented
For large projects, with a lot of transactional aware objects, it seems useful to define the
@Transactional
semantics at the class level, and override the settings at the method level as necessary. Consider the following example:At the class level, we have defined what we hoped would be the defaults for all methods within the class. For the method updateFoo(), we need to change the propagation level to REQUIRES_NEW, but want to re-use the defaults that have already been specified at the class level. So we added the
@Transactional
meta-data on the method. Once we have added just the propagation level to the method, we lose rollbackFor and timeout properties set at the class level - there is no form of inheritance.As a result, you must include all additional properties again on the method, the properties defined at the class level are completely ignored. The result of this is that we have to redundantly copy the properties onto the
@Transactional
declaration for every method from the class in order to retain them, which is unfortunate.What we were hoping for, was to be able to simply change the rollbackFor by appending an additional Exception at the class level and have all methods, only those with the
@Transactional
annotation that did not explicitly set the rollbackFor property, benefit from the change via inheritance. Instead, we would have to go back and systematically add the change to every method explicitly, instead of simply appending it to the rollbackFor property of the@Transactional
annotation at the class level.I can see that maybe this could introduce some problems with backwards compatibility. So, maybe Spring could introduce an additional property on the
@Transactional
annotation like: 'inherit=true', which would then signal that any unset properties should be inherited from the next higher level. So, if the method set the inherit=true property, then it should inherit any unset properties from the class. If the class has not set a property, then it would inherit from the TransactionManager defaults as expected.Affects: 3.0 GA
2 votes, 4 watchers
The text was updated successfully, but these errors were encountered: