2014-03-29 48 views
0

我做了一個在Oracle中運行但在Hibernate中出錯的插入查詢。插入查詢不在Hibernate中執行但在Oracle中

查詢:

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); 

當從春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); 

燦你請提出這裏發生了什麼問題?

回答

2

createQuery用於創建一個HQL查詢,它是Hibernate類似於SQL的自定義查詢語言。

你想要createSQLQuery

+0

感謝您的幫助:) – Sandeep

相關問題