java - hibernate 中有没有一种方法可以在一个字符串中操作多个查询

标签 java sql postgresql hibernate

我在我的网络项目中使用 hibernate 。我在 createSQLQuery(queryString) 中执行这行 String。下面是我在 queryString 中分配的值:

DROP TABLE monthlyevaluatedbudgettabletemp;
DROP TABLE monthlyadjustedbudgettabletemp;

CREATE TABLE monthlyevaluatedbudgettabletemp (budgetid bigint NOT NULL,
  approvedbudget numeric(19,2),
  april numeric(19,2),
  august numeric(19,2),
  budgetforyear bigint NOT NULL,
  december numeric(19,2),
  february numeric(19,2),
  january numeric(19,2),
  july numeric(19,2),
  june numeric(19,2),
  march numeric(19,2),
  may numeric(19,2),
  november numeric(19,2),
  october numeric(19,2),
  september numeric(19,2),
  branchid integer,
  accountid bigint,
  budgetlastyear bigint);

CREATE TABLE monthlyadjustedbudgettabletemp (adjustedid bigint NOT NULL,
  april numeric(19,2),
  august numeric(19,2),
  december numeric(19,2),
  february numeric(19,2),
  january numeric(19,2),
  july numeric(19,2),
  june numeric(19,2),
  march numeric(19,2),
  may numeric(19,2),
  november numeric(19,2),
  october numeric(19,2),
  september numeric(19,2),
  yeartodatemonth character varying(255),
  budgetid bigint);

INSERT INTO monthlyevaluatedbudgettabletemp SELECT * FROM monthlyevaluatedbudgettable where budgetforyear=2017;
INSERT INTO monthlyadjustedbudgettabletemp SELECT a.* from monthlyadjustedbudgettable as a join monthlyevaluatedbudgettable as e on a.budgetid=e.budgetid where e.budgetforyear = 2017

UPDATE monthlyevaluatedbudgettabletemp SET budgetforyear=2017,budgetlastyear=2016,april=0.00,approvedbudget=0.00,august=0.00,february=0.00,january=0.00,july=0.00,june=0.00,march=0.00,may=0.00,november=0.00,october=0.00,september=0.00,december=0.00;

UPDATE monthlyadjustedbudgettabletemp SET january=0.00,february=0.00,march=0.00,april=0.00,may=0.00,june=0.00,july=0.00,august=0.00,september=0.00,november=0.00,
october=0.00,december=0.00;

现在,当我使用 createSQLQuery(queryString).executeUpdate(); 运行它时。我遇到了这种错误。

org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query

现在我的问题是,有没有一种方法可以一次性操作 String.还是我必须将每个查询语句分开并一个一个地执行。这就像我想在 hibernate 中执行一个 .sql 文件。

最佳答案

您不能在 Hibernate 中一次运行多个 native 查询。

您必须分离查询,然后单独运行它们。

在 JDBC 中也是如此。

关于java - hibernate 中有没有一种方法可以在一个字符串中操作多个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40712072/

相关文章:

java - 从 JavaScript 转换为 Java 但没有给出相同的输出

SQL 语法错误 : "Missing Right Parenthesis"

sql - Postgres : Get value of a column corresponding to max of other column in a group

xml - 从 Postgres 中的 xpath 输出中删除大括号

java - Hibernate:合并parentEntity时childEntity null id

postgresql - 为什么无法创建分区表

java - 解压缩 zip 文件超过 100% 时的百分比计算!

java - 运行startNetworkServer时出错

java - 使用 JsonReader 将缓存的 Json 文件读取为 ByteArray

sql - SQL 查询的最大长度