Hibernate 如何在hql中访问映射的键或值
假设我有以下课程:Hibernate 如何在hql中访问映射的键或值,hibernate,map,Hibernate,Map,假设我有以下课程: @Entity public class CompanyImpl extends BaseEntity { @OneToMany(cascade=CascadeType.ALL) private Map<Cat,Flight> flightCats; 但它不起作用:( 编辑:在谷歌搜索之后,我发现这条建议使用θ样式联接的查询: from CompanyImpl co left join co.flightCats cf where (cf
@Entity
public class CompanyImpl extends BaseEntity {
@OneToMany(cascade=CascadeType.ALL)
private Map<Cat,Flight> flightCats;
但它不起作用:(
编辑:在谷歌搜索之后,我发现这条建议使用θ样式联接的查询:
from CompanyImpl co left join co.flightCats cf where
(cf in indices(co.flightCats)) and (cf.name = 'Ocean')
这个查询对我来说太复杂了,我无法理解。有趣的是,它通过飞行对象的名称(地图的值)来限制结果,无论我使用的是索引()还是元素()
有人能给我解释一下发生了什么吗???在(N)Hibernate文档中没有很好的记录,但是它被记录了: 它有一些特殊的HQL函数:
index()
和elements()
试着这样做:
from CompanyImpl co where indices(co.flightCats).name='Meow'
NHibernate HQL文档在中提到了索引和元素。当您说“不起作用”时,异常?org.hibernate.QueryException:无法解析属性:cat of:org.hibernate.tutorial.annotations.CompanyImpl co where co.flightCats.cat.name='Meow']不幸的是,由于提到index(),我得到了一个NullPointerException+1。我以前没有注意到这个函数。
from CompanyImpl co where indices(co.flightCats).name='Meow'