问题描述
假设我有一个地图:
< map name =externalIdstable =album_external_ids>
< key column =album_idnot-null =true/>
< map-key-many-to-many class =Majorcolumn =major_id/>
< element column =external_idtype =stringnot-null =true/>
< / map>
如何使HQL意思是select entities where map key's id ==:foo and map value ==:bar?
我可以使用选择专辑加入相册相册join album.externalIds ids
但是我怎么会引用ids的键和值呢?
ids.key.id =:foo和ids.value =:bar不起作用,而hibernate文档对此主题没有保留。
天真的方法这不起作用:
从专辑相册中选择相册join album.externalIds externalId
其中index(externalId).id = foo and externalId =:bar
和
从专辑相册中选择相册join album.externalIds externalId join index(externalId)major
其中major.id =:foo和externalId =:bar
我相信您的查询应该如下所示:
相册相册album.externalIds ['foo'] ='bar'
希望有帮助, p>
VincentGiguère
Suppose I have a map:
<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>
How do I make a HQL meaning "select entities where map key's id == :foo and map value == :bar"?
I can join it using select album from Album album join album.externalIds ids
But how would I then refer to ids' key and value?ids.key.id = :foo and ids.value = :bar doesn't work, and hibernate doc is silent on this topic.
Naive approaches that didn't work:
select album from Album album join album.externalIds externalId where index(externalId).id = :foo and externalId = :bar
and
select album from Album album join album.externalIds externalId join index(externalId) major where major.id = :foo and externalId = :bar
I believe that your query should look like:
select album from Album album where album.externalIds['foo'] = 'bar'
Hope that helps,
Vincent Giguère
这篇关于加入映射并参考其在HQL中的键/值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!