In principle I have more or less the following code
@Component
public class SomeService {
@Autowired
private SettingsService settingsService;
@Autowired
private OtherService otherService;
@Transactional
public void storeData(Data d) {
settingsService.set("setting1", d.getSetting1());
settingsService.set("setting2", d.getSetting2());
settingsService.set("setting3", d.getSetting3()); // no effect
// do something with otherService
}
@Transactional
public void storeData2(Data d) {
settingsService.set("setting1", d.getSetting1());
settingsService.set("setting3", d.getSetting3());
settingsService.set("setting2", d.getSetting2()); // no effect
// do something with otherService
}
@Transactional
public void storeData3(Data d) {
settingsService.set("setting1", d.getSetting1());
settingsService.set("setting2", d.getSetting2()); // no effect
// settingsService.set("setting3", d.getSetting3());
// do something with otherService
}
@Transactional
public void storeData4(Data d) {
settingsService.set("setting1", d.getSetting1());
settingsService.set("setting2", d.getSetting2());
settingsService.set("setting3", d.getSetting3());
settingsService.set("setting3", "doesn't matter"); // works but hacky
// do something with otherService
}
// @Transactional
public void storeData5(Data d) {
settingsService.set("setting1", d.getSetting1());
settingsService.set("setting2", d.getSetting2());
settingsService.set("setting3", d.getSetting3()); // works but no TX :(
// calls to otherService go boom because there is no TX
}
}
Transaction management is enabled in the main configuration via a simple @EnableTransactionManagement
.
Both SettingsService
and OtherService
store some stuff in the same relational database.
Now when I call some of the storeData
methods, it is always the last call to settingsService
that has no effect, i.e., the changes are not persisted in the database (see storeData
, storeData2
and storeData3
). If I execute the last line twice (or try to persist some bogus data), everything works but this is obviously a hack (storeData4
).
Curiously in all cases the calls to OtherService
work with everything being persisted as it should.
SettingService
's set
method can be either annotated with @Transactional
or not; the described faulty behavior does not change. It is only when I remove @Transactional
from SomeService
's storeData
method that all calls to settingsService
have an effect (storeData5
). However I really want that transaction (and I need it for dealing with otherService
).
So the behavior above shows that the services calls work in principle but not all at the same time. I debugged everything and all variables are set to the correct values. I have no idea what the reason for this behavior could be and how to debug it any further.