简体   繁体   English

Spring Data JPA-大规模更新不起作用

[英]Spring Data JPA - Massive update does not work

I have a basic SpringBoot 2.1.1.RELEASE app. 我有一个基本的SpringBoot 2.1.1.RELEASE应用程序。 Using Spring Initializer, JPA, embedded Tomcat, and package as an executable JAR with a restful architecture I have this repository: 使用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);


}

but does not update the rows in the DB 但不会更新数据库中的行

Try this code, 试试这个代码,

    @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);

if any issue inform. 如果有任何问题,请告知。

I am not sure about what you want to do, but as an update query, you can also use the save() function from the CrudRepository by selecting the id primary key of the raw you want to update in your table. 我不确定要做什么,但是作为更新查询,您还可以通过选择要在表中更新的Raw的ID主键来使用CrudRepositorysave()函数。

An other point is the List<Long> notificationIdList parameters that you want to take into account, are you sure that you can give a list to @Param ? 另一点是您要考虑的List<Long> notificationIdList参数,您确定可以将列表提供给@Param吗? If not, you can use a for loop on the elements of the list and call the query function changeNotificationListReadStatus() at each iteration. 如果没有,则可以在列表的元素上使用for循环,并在每次迭代时调用查询函数changeNotificationListReadStatus()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM