Using Spring Data JPA I have the following thread inside a single transaction (REQUIRES_NEW):
Delete a set of custom forecasts using this JPA Spring data repository method.
@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);
Insert new custom forecasts and save the main object (event).
eventRepository.save(event);
When this service ends, the commit is performed by AOP, but only works in the first attemp ... not in the following ...
How can I manage this situation without repeating the records of event events and updating each of them internally?
UPDATE
I tried with this and it does not work (the adapter inserts the objects that I delete earlier):
@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); }
source share