更新时间:2022-11-03 16:06:10
By default @Query
is considered to be a select
query. To make it be treated as a modifying query, use @Modifying
annotation:
Indicates a method should be regarded as modifying query.
So, you should write your repository the following way:
public interface PartRepo extends PagingAndSortingRepository<Part,Long> {
@Modifying
@Query(value = "SET IDENTITY_INSERT PART ON", nativeQuery = true)
public void enableInsertIdentity();
@Modifying
@Query(value = "SET IDENTITY_INSERT PART OFF", nativeQuery = true)
public void disableInsertIdentity();
}