3
我已經看了一下網絡,無法真正找到明確的答案。如何創建一個休眠獨特的查詢
我有兩個表A和B. B是A的孩子,我需要得到基於A.
的一些限制,例如的B不同的屬性列表:
SQL:
select distinct sirm.attribute
from store_item_received_material sirm
where sirm.store_item_id in (select si.id from store_item si where si.program_id = 9 and si.customer_id = 1 and si.date_processed is not null);
當然,SQL的工作很好。
現在,我需要在我的項目中運行這個。
我正在運行hibernate 3.3.1。我試過如下:
@NamedNativeQueries ({
@NamedNativeQuery (name = "select.distinct.sirm.for.customer.program", query = "select distinct(sirm.attribute) as attribute from store_item_received_material as sirm where sirm.store_item_id in (select si.id from store_item as si where si.customer_id = ? and si.program_id = ? and si.date_processed is not null)")
})
但失敗,出現以下錯誤:
嵌套的例外是org.hibernate.cfg.NotYetImplementedException:純天然的標量的查詢尚不支持
所以,我想如下:
@NamedNativeQueries ({
@NamedNativeQuery (name = "select.distinct.sirm.for.customer.program", query = "select distinct(sirm.attribute) as attribute from store_item_received_material as sirm where sirm.store_item_id in (select si.id from store_item as si where si.customer_id = ? and si.program_id = ? and si.date_processed is not null)", resultClass=StoreItemReceivedMaterial.class)
})
@SqlResultSetMapping(name = "select.distinct.sirm.for.customer.program", [email protected](entityClass = StoreItemReceivedMaterial.class))
但是,由於該對象是一個實體對象,並沒有一個ID列,所以不起作用。
那麼,如何做到這一點
貌似http://stackoverflow.com/questions/263850/的重複你怎麼做,創建一個獨特的查詢在hql – FoxyBOA 2011-02-15 05:38:49