首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用HQL查询具有特定集合条目的实体

使用HQL查询具有特定集合条目的实体
EN

Stack Overflow用户
提问于 2009-11-25 09:08:19
回答 1查看 1.7K关注 0票数 2

我有Item对象,它有一个属性集合,定义为映射。现在我想检索所有具有特定属性的对象(通过namelocalevalue)

Item映射的期望:

代码语言:javascript
复制
<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 ( :keyLocalizedKey:valueString)

代码语言:javascript
复制
from Item item
where item.attributes[:key] = :value

不工作,并产生以下输出

代码语言:javascript
复制
error: composite-index appears in []

我在查询中使用普通SQL创建了一个解决方案。但是我想知道是否有办法在HQL中做到这一点。

我的普通sql解决方案:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2009-11-25 17:15:44

文档提示index()操作符应该从映射中返回键。考虑到您的键是一个复合对象,我不完全确定您在查询中能够用它做什么。很抱歉,在给你这个建议之前,我没能对它进行测试,但我想试着看看你得到了什么:

代码语言:javascript
复制
from Item item join item.attributes attr where attr.index().name = :name 
       and attr.index().locale = :locale and attr.value = :value
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1795594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档