2012-06-19 34 views
0

我不能找出爲什麼總是拋出此表達一個NullPointerException:Hibernate的HQL的createQuery NullPointerException異常

String jpql = "DELETE Trend t WHERE t.owner = :owner AND t.shapeId = :shapeid AND t.security = :security AND t.timeframe = :timeframe";   
int rows = 0;  
try {   
Query q = em.createQuery(jpql, Trend.class); // this line throw the exception 
... 

其他請求成功執行。

回答

1

第二個參數應該是查詢將返回的對象的類型。但是這個查詢不返回任何東西,因爲它是一個刪除查詢。

我不知道它爲什麼會拋出NullPointerException(它不應該),但可以肯定的是,您應該使用沒有Class參數的createQuery()方法。

+0

Thx,但爲什麼不應該使用沒有Class參數的createQuery? –

+0

這對我很有用,我發現它沒有class arg。在官方文檔中也是如此.. http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/batch.html#batch-direct –

相關問題