2015-11-06 74 views
0

我在我的應用程序中使用了oracle。org.hibernate.exception.SQLGrammarException:無法執行本地批量操作查詢

我已經使用這個代碼的問題:

import org.hibernate.Hibernate; 
    import org.hibernate.SQLQuery; 
    import org.hibernate.Session; 
    import org.hibernate.Query; 
    .... 
    .... 
    ..... 

    public void insertGR(String id,String num) { 


       String query = "execute md_pkg.insert_Gr("+id+"," + num + ")"; 


       SQLQuery sqlQuery = this.getSession().createSQLQuery(query); 
       sqlQuery.executeUpdate(); 



      } 
在JBoss中CONSOL

我有這樣的錯誤:

SQL Error: 900, SQLState: 42000 
ORA-00900: invalid SQL statement 


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

,但是當我用sqldevelopper我沒有任何問題

execute execute md_pkg.insert_Gr(9,25) 

回答

0

ORA-900: Invalid SQL statement應該給你足夠的線索,告訴你發生了什麼事情/錯誤。要執行的語句不是SQL,它試圖調用PL/SQL存儲過程。所以,與其

"execute md_pkg.insert_Gr("+id+"," + num + ")" 

你應該(也許吧!我不知道,Hibernate在所有),而

"call md_pkg.insert_Gr("+id+"," + num + ")" 

"begin md_pkg.insert_Gr("+id+"," + num + "); end;" 

,而不是和使用SQLQuery類嘗試和找到能夠執行存儲過程或匿名PL/SQL塊的內容。 PS:我根本不知道Hibernate,所以我不能幫你找到正確的類。

相關問題