我想用非实体的集合进行JPQL查询。这是我的Table实体:

@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;
...

然后我尝试进行这样的查询
select count(*) from table where table.tableResults['somekey'].value='somevalue'

但我得到以下异常:
Cannot create element join for a collection of non-entities!

有什么建议吗?

谢谢你的时间

编辑:

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

最佳答案

JPA 2 spec(第139页)定义了KEY()VALUE()函数来访问键和地图值元素集合的值:

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

关于java - JPQL查询非实体的集合,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9311011/

10-08 22:16
查看更多