假设我有一张地图:
<map name="externalIds" table="album_external_ids">
<key column="album_id" not-null="true"/>
<map-key-many-to-many class="Major" column="major_id"/>
<element column="external_id" type="string" not-null="true"/>
</map>
如何使HQL意味着“选择地图键的id ==:foo和map value ==:bar的实体”?
我可以使用select album from Album album join album.externalIds ids
加入
但是,我如何才能引用ids的关键和价值呢?
ids.key.id =:foo和ids.value =:bar不起作用,hibernate doc对此主题保持沉默。
天真的方法不起作用:
select album from Album album join album.externalIds externalId
where index(externalId).id = :foo and externalId = :bar
和
select album from Album album join album.externalIds externalId join index(externalId) major
where major.id = :foo and externalId = :bar
答案 0 :(得分:4)
我相信您的查询应如下所示:
select album from Album album where album.externalIds['foo'] = 'bar'
希望有所帮助,
VincentGiguère