考虑以下属性:
public class BusinessUnit {
...
@ElementCollection
@MapKeyJoinColumn(name = "permissionId")
@Enumerated(EnumType.STRING)
private Map<Permission, BusinessUnitPermissionApplyType> permissions;
...
}
以下查询不适用于EclipseLink:
List<BusinessUnit> foundBUs = new JPAQuery(em)
.from(qbu)
.where(qbu.permissions.containsKey(permission))
.list(qbu);
它给出错误:
Exception Description: Syntax error parsing [select bu
from BusinessUnit bu
where containsKey(bu.permissions,?1)].
[37, 68] The expression is not a valid conditional expression.
当然,JPQL中没有containsKey
函数。因此可以正确模拟containsKey
吗?例如,通过执行子查询。
执行相同查询的另一种方法是什么?我试图加入permissions
,即:
.join(qbu.permissions)
但是这没有用,因为这个表达式不允许检查键的值。真正有用的是:
.joinKey(qbu.permissions, qperm)
.where(qperm.eq(permission))