gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 14:18:12 24 4
gpt4 key购买 nike

我在我的网络项目中使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com