JPA @Modifying注解 jpql语句更新以及删除

JPA @Modifying注解解释

这个注解在JPA中经常出现,是为了通知jpa,这是一个update或者delete操作,在更新或者删除操作时,此注解必须加,否则就会抛出异常,注:jpa不支持insert语句
以下就是这个注解使用示例`

/**
 * Created by w on 2018/12/24.
 */
@Repository
public interface NoticeCustomerRepository extends JpaRepository<NoticeCustomer, Long> {
    @Modifying
    @Query("update NoticeCustomer n set n.isRead =true where n.noticeId in :ids and n.customerId = :customerId")
    void setRead(@Param("ids") Long[] ids, @Param("customerId") Long customerId);
}

解决必须JPA更新以及删除时必须知道整个完整对象的尴尬

猜你喜欢

转载自blog.csdn.net/wgxu123/article/details/87931323