gpt4 book ai didi

java - 插入查询不是在 Hibernate 中执行而是在 Oracle 中执行

转载 作者:行者123 更新时间:2023-12-02 06:00:18 24 4
gpt4 key购买 nike

我做了一个在 Oracle 中运行的插入查询,但在 Hibernate 中出现错误。

查询:

insert into tmptable
(dcol1, ncol1, ncol2)
select TRUNC(hie.timestamp), min(hie.eventid), count(1)
from eventtable hie
where hie.eventid >= 123
and hie.eventtype = 'NEW'
and hie.key like 'SYS_%'
and hie.timestamp between trunc(sysdate - 3) and
trunc(sysdate) + to_dsinterval('00 23:59:59')
group by TRUNC(hie.timestamp)
order by TRUNC(hie.timestamp);

从 Spring MVC + Hibernate 运行时,出现以下错误:

HTTP Status 500 - Request processing failed; 
nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: 1 near line 1, column 113 [insert into tmp$genutil .....]

下面是插入数据的代码:

/* TMP_TABLE_INSERT member variable has above Insert query */
Query query = getSession().createQuery(TMP_TABLE_INSERT);
int result = query.executeUpdate();
System.out.println("Rows affected: " + result);

您能建议一下这里出了什么问题吗?

最佳答案

createQuery 用于创建 HQL 查询,它是 Hibernate 的自定义查询语言,类似于 SQL。

您需要createSQLQuery

关于java - 插入查询不是在 Hibernate 中执行而是在 Oracle 中执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22726128/

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