且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在不使用结果集的情况下使用Spring Data JPA执行本机SQL服务器查询

更新时间: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();
}

相关阅读

技术问答最新文章