Ant*_*edo 7 jpa eclipselink spring-data spring-data-jpa
使用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);
Run Code Online (Sandbox Code Playgroud)插入新用户的预测并保存主对象(事件).
eventRepository.save(event);
Run Code Online (Sandbox Code Playgroud)当这个服务完成时,提交是由AOP完成的,但只能在第一次尝试时...而不是在下一个...
如何在不迭代事件的预测条目并更新内部的每个条目的情况下管理这种情况?
UPDATE
我尝试了它,它不起作用(适配器插入我之前删除的对象):
@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);
}
Run Code Online (Sandbox Code Playgroud)
小智 5
休眠更改了命令的顺序。它按以下顺序工作:以特殊顺序执行所有SQL和二级缓存更新,以免违反外键约束:
1. Inserts, in the order they were performed
2. Updates
3. Deletion of collection elements
4. Insertion of collection elements
5. Deletes, in the order they were performed
Run Code Online (Sandbox Code Playgroud)
确实是这样。刷新时,Hibernate在delete语句之前执行所有插入操作。可能的选项是:
1.在删除后立即显式调用entityManager.flush()。或2.尽可能更新现有行,然后从其余位置创建ToBeDeleted List。这将确保使用新值更新现有记录,并保存全新的记录。
| 归档时间: |
|
| 查看次数: |
6157 次 |
| 最近记录: |