gpt4 book ai didi

hibernate - 如何访问hql中 map 的键或值

转载 作者:行者123 更新时间:2023-12-03 08:10:45 24 4
gpt4 key购买 nike

假设我有以下类(class):

@Entity
public class CompanyImpl extends BaseEntity {

@OneToMany(cascade=CascadeType.ALL)
private Map<Cat,Flight> flightCats;

Cat 和 Flight 类都有一个“name”属性。我怎样才能:

  1. 选择在其 flightCats map 中有名为“Meow”的猫的公司
  2. 选择在其 flightCats map 中将航类命名为“Ocean”的公司

我想到了类似的东西

from CompanyImpl co where co.flightCats.cat.name='Meow'

但它不起作用:(


编辑: 经过一番谷歌搜索后,我发现了这个 link建议使用 theta 样式连接的查询:

from CompanyImpl co left join co.flightCats cf where 
(cf in indices(co.flightCats)) and (cf.name = 'Ocean')

这个查询对我来说很奇怪,我无法理解。有趣的是,无论我使用 indices() 还是 elements(),它都通过 Flight 对象的名称限制结果( map 的值)!!!

谁能给我解释一下这是怎么回事??!!

最佳答案

它在 (N)Hibernate 文档中没有很好地记录,但记录在案:

它有特殊的 HQL 函数:indices()elements()

尝试这样的事情:

from CompanyImpl co where indices(co.flightCats).name='Meow'

NHibernate HQL 文档在 chapter 14 中提到了索引和元素.

关于hibernate - 如何访问hql中 map 的键或值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14202884/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com