javax.persistence.TransactionRequiredException: Executing an update/delete query

在使用@Query中的语句包含数据更新和删除的地方,如果没有加@Transactional和@Modifying那么可能会报javax.persistence.TransactionRequiredException: Executing an update/delete query错误
解决办法就是加上那两个注解

public interface ResumeRepository extends PagingAndSortingRepository {
    @Transactional
    @Modifying
    @Query("update Resume r set r.isDefault = :isDefault where r.user = :user") 
    public int setIsDefault(@Param("user") User user, @Param("isDefault") int isDefault);

你可能感兴趣的:(javax.persistence.TransactionRequiredException: Executing an update/delete query)