【发布时间】:2011-02-15 03:50:47
【问题描述】:
我浏览了网络,并没有真正找到明确的答案。
我有两个表 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 工作得很好。
现在,我需要在我的项目中运行它。
我正在运行休眠 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", entities=@EntityResult(entityClass = StoreItemReceivedMaterial.class))
但这也不起作用,因为该对象是实体对象并且没有 ID 列。
所以,关于如何做到这一点的任何帮助
【问题讨论】:
-
我看到了相同的内容并打算在我的原始帖子中引用