我有Item对象,它有一个属性集合,定义为映射。现在我想检索所有具有特定属性的对象(通过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发布于 2009-11-25 17:15:44
文档提示index()操作符应该从映射中返回键。考虑到您的键是一个复合对象,我不完全确定您在查询中能够用它做什么。很抱歉,在给你这个建议之前,我没能对它进行测试,但我想试着看看你得到了什么:
from Item item join item.attributes attr where attr.index().name = :name
and attr.index().locale = :locale and attr.value = :valuehttps://stackoverflow.com/questions/1795594
复制相似问题