JPQL查询非entites的集合 [英] JPQL querying a collection of non-entites

查看:159
本文介绍了JPQL查询非entites的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一组非实体制作一个JPQL查询。这是我的表实体:

I want to make a JPQL query with a collection of non entities. This is my Table entity :

@Entity
@Table(name = "ct_table")
public class Table {
...

@CollectionOfElements(fetch = FetchType.EAGER)
@JoinTable(name = "ct_table_result", joinColumns = @JoinColumn(name = "tableId"))
@MapKey(columns = { @Column(name = "label") })
@Column(name = "value")
private Map<String, String> tableResults;
...

然后我尝试进行这样的查询

then I try to make a query like this

select count(*) from table where table.tableResults['somekey'].value='somevalue'

但我收到以下异常:

Cannot create element join for a collection of non-entities!

任何建议??

感谢你的时间

编辑:

我使用JPA 1和hibernate 3.3。 JBoss 5中的默认库

I use JPA 1 and hibernate 3.3. Default libraries in JBoss 5

推荐答案

JPA 2规范(第139页)定义 KEY() VALUE()访问键的函数和映射值元素集合的值:

The JPA 2 spec (page 139) defines the KEY() and VALUE() functions to access the key and the value of a map-valued element collection:

select count(t.id) from Table t 
where KEY(t.tableResults) = 'somekey' and VALUE(t.tableResults) = 'somevalue'

这篇关于JPQL查询非entites的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆