![](/img/trans.png)
[英]Exception while executing batch update/insert on Hibernate/Oracle
[英]Insert query not executing in Hibernate but in Oracle
我做了一個在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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.