当没有预期结果时,返回了一个结果。SpringBoot/Postgresql

当没有预期结果时,返回了一个结果。SpringBoot/Postgresql,postgresql,hibernate,spring-boot,jpa,Postgresql,Hibernate,Spring Boot,Jpa,我只想选择表中的最后一行,并在变量中返回这个int。 这是我的存储库中的方法: @Transactional @Modifying @Query(value="SELECT category_id FROM category ORDER BY category_id DESC LIMIT 1\r\n", nativeQuery = true) int selectLastRecord(); 当我用以下代码调用方法时: int categoryId = this.categoryReposit

我只想选择表中的最后一行,并在变量中返回这个int。 这是我的存储库中的方法:

@Transactional
@Modifying
@Query(value="SELECT category_id FROM category ORDER BY category_id DESC LIMIT 1\r\n", nativeQuery = true)
int  selectLastRecord();
当我用以下代码调用方法时:

int categoryId = this.categoryRepository.selectLastRecord();
我有一个错误:

org.postgresql.util.PSQLException: A result was returned when none was expected.

需要修改注释的查询包括INSERT、UPDATE、DELETE和DDL语句

添加
@Modifying
注释表示该查询不适用于SELECT查询

因此,删除
@修改


参考

删除修改注释。它必须用于修改数据库的查询,即插入、更新或删除。只需删除
@Modifying