2015-11-13 46 views
2

我是新來的休眠和我有這個SQL查詢其作品完美內Hibernate的連接查詢 - SQL查詢目前不支持迭代

SELECT count(*) as posti_disponibili from occupazione t inner join 
(select id_posto_park, max(date_time) as MaxDate from occupazione 
group by id_posto_park) tm on t.id_posto_park = tm.id_posto_park and 
t.date_time = tm.Maxdate and t.isOccupied = 0 

這給了我所有的最後一項與isOccupied = 0

我將它移植到Hibernate中,我試圖用

result = ((Integer) session.createSQLQuery(query).iterate().next()).intValue() 

返回posti_disponibili但我得到這個例外

java.lang.UnsupportedOperationException: SQL queries do not currently support iteration 

我該如何解決這個問題?我找不到相當於HQL查詢

謝謝

+0

您的查詢返回單個值。你爲什麼要迭代? –

回答