@Transactional 更新後、非同期クエリで最新の結果をクエリできなくなります

   @Transactional(rollbackFor = AssetException.class)
    @Override
	public ServiceResult<Integer> editAssetArea(AssetArea assetArea) {
		//更新前查询
		int updateCount = assetAreaMapper.updateByPrimaryKeySelective(assetArea);

		//同异步调用
        threadPoolTaskExecutor.execute(() ->
                syncArea2Ams(id,assetArea.getUpdateUser(),assetArea.getUpdateUserName()));

		return ServiceResultUtil.success(true,1,"更新成功",updateCount);
	}


    @Override
	public void syncArea2Ams(Long id,String userCode,String userName) {
		log.info("syncArea2Ams_select_start ");
        ServiceResult<AssetArea> result = getAssetAreaById(id);
		log.info("syncArea2Ams_select_end  查询不出最新结果 ");

}

原因分析: @Transactional は、メソッドの実行後にのみトランザクションをコミットします。中間ロジックは結果を前処理するだけです。

è¿éæå¥å¾çæè¿°

解決策: ID を渡さずにパラメータを渡し、オブジェクトを直接転送します。

 

 

おすすめ

転載: blog.csdn.net/LOVE_sel/article/details/89715198
おすすめ