【发布时间】:2009-11-25 09:08:19
【问题描述】:
我有 Item 对象,它们具有定义为 map 的 属性集合。现在我想检索所有具有特定属性的对象(name、locale 和 value)
Item 映射专家:
<map table="ITEM_ATTRIBUTES" name="attributes">
<key column="item_id" foreign-key="fk_itmr_attrbts_itmrs"/>
<composite-index class="LocalizedKey">
<key-property name="name" column="name"/>
<key-property name="locale" column="locale" length="32"/>
</composite-index>
<element column="value" type="escapedString" not-null="true"/>
</map>
此 HQL(:key 为 LocalizedKey 和 :value 为 String)
from Item item
where item.attributes[:key] = :value
不起作用并产生以下输出
error: composite-index appears in []
我通过在查询中使用纯 SQL 创建了一个解决方法。但我想知道是否有办法在 HQL 中做到这一点。
我的普通 sql 解决方法:
select i.* from items i
left join item_attributes a on a.item_id = i.id
where a.name = :name
and a.locale = :locale
and a.value = :value
【问题讨论】:
标签: sql hibernate collections hql