2011-08-08 46 views
11

我需要HQL是目前:Hibernate的新關鍵字具有鮮明

select distinct a from Asset as a where ... 

,並更改爲

select new com.org.AssetDTO(a.id, a.address, a.status) from Asset as a where ... 

我的問題是用不同的關鍵字。它在哪裏屬於您正在使用新的對象查詢類型的hql查詢。一個想法是使用一個子選擇,並在那裏有獨特的選擇。我已經嘗試加入distinct a.id但這不起作用。

回答

16

確定爲興趣的人正確的語法是

select distinct new com.org.AssetDTO(a.id, a.address, a.status) from Asset as a where ... 
+0

這是否意味着您的查詢的結果,是不是受AssetDTO equals()方法? – Leon

+0

爲什麼查詢的結果會受到equals()方法的影響?也許我不理解你的問題 – dstarh

+0

'distinct new com.org.AssetDTO'相當於''不同於a資產',而不等價於'distinct(a.id,a.address,a.status)'。實體的所有字段用於選擇DISTINCT? – Leon