I have Item
objects which have a collection of attributes defined as a map. Now I want to retrieve all objects which have a specific attribute (by name
, locale
and value
)
An expecert of the Item
mapping:
<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>
This HQL (with :key
as LocalizedKey
and :value
as String
)
from Item item
where item.attributes[:key] = :value
doesn't work and produces the following output
error: composite-index appears in []
I created a workaround by using plain SQL in my query. But i'd like to know if there is a way to do this in HQL.
my plain-sql workaround:
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