【发布时间】:2019-10-13 07:47:50
【问题描述】:
我只想选择表中的最后一行并将这个 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.
【问题讨论】:
-
删除修改注释。它必须用于修改数据库的查询,即插入、更新或删除。
-
删除
@Modifying
标签: postgresql hibernate spring-boot jpa