[英]Spring Data JPA - Massive update does not work
我有一个基本的SpringBoot 2.1.1.RELEASE应用程序。 使用Spring Initializer,JPA,嵌入式Tomcat和作为具有宁静架构的可执行JAR程序包,我有了这个存储库:
@Repository
public interface MenuPriceAlertNotificationRepository
extends CrudRepository<MenuPriceAlertNotification, Long> {
@Transactional
@Modifying
@Query("update MenuPriceAlertNotification n set n.read = :status where n.id in :notificationIdList and n.user.id = :userId")
void changeNotificationListReadStatus( @Param("notificationIdList") List<Long> notificationIdList,
@Param("userId") long userId,
@Param("status") boolean status);
}
但不会更新数据库中的行
试试这个代码,
@Transactional(propagation =Propagation.REQUIRED,isolation=Isolation.SERIALIZABLE,readOnly=false,transactionManager="transactionManager")
@Query("update MenuPriceAlertNotification n set n.read = :status where n.id in :notificationIdList and n.user.id = :userId")
void changeNotificationListReadStatus( @Param("notificationIdList") List<Long> notificationIdList,
@Param("userId") long userId,
@Param("status") boolean status);
如果有任何问题,请告知。
我不确定要做什么,但是作为更新查询,您还可以通过选择要在表中更新的Raw的ID主键来使用CrudRepository
的save()
函数。
另一点是您要考虑的List<Long> notificationIdList
参数,您确定可以将列表提供给@Param
吗? 如果没有,则可以在列表的元素上使用for循环,并在每次迭代时调用查询函数changeNotificationListReadStatus()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.