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更新以及删除时必须知道整个完整对象的尴尬
本文详细解析了JPA中的@Modifying注解,强调其在update和delete操作中的必要性,并提供了具体的应用实例。了解如何正确使用此注解,避免JPA更新和删除操作中的常见错误。
834

被折叠的 条评论
为什么被折叠?



