0
我有像這樣一個特定的方法服務實現:理解 - 春天
public class ExampleServiceImpl implements ExampleService {
@AutoWired
@Resource
private RecordRepository recordRepository;
private void processRecord() {
// some code here
}
@Transactional(readOnly=false)
public void processRecord(Record a) {
Record original = getOriginal(a);
recordRepository.saveChanges(a,original);
}
}
該紀錄類是對象圖的根對象。 RecordRepository看起來像下面的子存儲庫,以保存圖中對象的各種子對象。
public class RecordRepository extends BaseRepository<Record> {
@AutoWired
@Resource
private IDao databaseDao;
@AutoWired
@Resource
private SubRecordRepository subRecordRepository;
public void saveChanges(Record a, Record b) {
//Perform some processing on a, b
for(SubRecord subA : a.getSubRecords()) {
subRecordRepository.saveChanges(subA);
}
databaseDao.updateRecord(a);
}
}
public class DatabaseDao extends NamedParameterJdbcDaoSupport implements IDao {
@Autowired
public DatabaseDao(@Qualifier("org.somewhere.Datasource") DataSource ds) {
super();
this.setDataSource(ds);
}
public void updateRecord(Record inRecord) {
String query = (String) sql.get("updateRecord");
SqlParameterSource parms = new BeanPropertySqlParameterSource(inRecord);
getNamedParameterJdbcTemplate().update(query, parms);
}
public void insertSubRecord(SubRecord inSubRecord) {
String query = (String) sql.get("insertSubRecord");
SqlParameterSource parms = new BeanPropertySqlParameterSource(inSubRecord);
getNamedParameterJdbcTemplate().insert(query, parms);
}
// other update and insert methods
}
該事務是否將應用於涉及來自processRecord調用的所有相關插入\更新?換句話說,如果插入或更新失敗,以前調用的來自ExampleServiceImpl.processRecord的插入和更新是否會回滾?