Spring Data JPA を使用すると、同じトランザクション (REQUIRES_NEW) 内に次のフローがあります。
この Spring Data JPA リポジトリ メソッドを使用して、一連のユーザーの予測を削除します。
@Query(value = "DELETE FROM TRespuestaUsuarioPrediccion resp WHERE resp.idEvento.id = :eventId AND resp.idUsuario.id = :userId") @Modifying void deleteUserPredictions(@Param("userId") int userId, @Param("eventId") int eventId);
新しいユーザーの予測を挿入し、マスター オブジェクト (イベント) を保存します。
eventRepository.save(event);
このサービスが終了すると、コミットは AOP によって行われますが、最初の試行でのみ機能します...次の試行では機能しません...
イベントの予測エントリを反復処理して内部の各エントリを更新せずに、この状況を管理するにはどうすればよいですか?
アップデート
私はそれを試してみましたが、うまくいきません(アダプターは以前に削除したオブジェクトを挿入します):
@Transactional(propagation=Propagation.REQUIRES_NEW, rollbackFor=PlayTheGuruException.class)
private void updateUserPredictions(final TUsuario user, final TEvento event, final SubmitParticipationRequestDTO eventParticipationRequestDTO)
{
eventRepository.deleteUserPredictions(user.getId(), event.getId());
EventAdapter.predictionParticipationDto2Model(user, event, eventParticipationRequestDTO);
eventRepository.save(event);
}