【问题标题】:A result was returned when none was expected. SpringBoot/Postgresql当没有预期结果时返回了结果。 SpringBoot/Postgresql
【发布时间】: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


【解决方案1】:

需要@Modifying 注释的查询包括 INSERT、UPDATE、DELETE 和 DDL 语句。

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

所以删除@Modifying

参考Modifying

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    • 2016-06-28
    • 2021-01-27
    • 1970-01-01
    • 1970-01-01
    • 2015-09-16
    相关资源
    最近更新 更多