【问题标题】:Hibernate executeUpdate() throws exception for PostgreSQL native query with returning *Hibernate executeUpdate() 为 PostgreSQL 本机查询抛出异常并返回 *
【发布时间】:2019-03-15 10:17:40
【问题描述】:

Hibernate executeUpdate() 用于插入或更新本机查询,returning * 给出异常,并且也不更新表。

SQLQuery query = session.createSQLQuery(
      "INSERT INTO public.account (username) VALUES ('xx'), ('yy'), ('zz') RETURNING user_id");

Transaction tx = session.beginTransaction();
query.executeUpdate();
tx.commit();

例外:

org.postgresql.util.PSQLException: 预期没有结果时返回了结果。

【问题讨论】:

    标签: postgresql hibernate sql-returning


    【解决方案1】:

    executeUpdate() 仅适用于 SQL 语句不返回结果行的情况。

    请改用iterate()list()scroll()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-02
      • 1970-01-01
      • 2015-03-10
      • 2018-07-20
      • 2015-09-22
      • 1970-01-01
      • 2013-11-13
      • 1970-01-01
      相关资源
      最近更新 更多