我的实体映射如下:
public class EntertainmentContentBean implements Serializable, Cloneable {
.
.
.
@ManyToMany
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
@JoinTable(schema = "etmt", name = "content_operator", joinColumns = @JoinColumn(name = "content_id"), inverseJoinColumns = @JoinColumn(name = "operator_id"))
public Set<Operator> getOperators() {
return operators;
}
.
.
.
}
我有一个特定的要求,我想根据以下标准检索EntertainmentContentBean记录:
我尝试了以下查询,但它没有返回预期的记录:
SELECT NEW MAP (content AS content, id AS record_id)
FROM EntertainmentContentBean contentEntry
WHERE (contentEntry.operators is empty or (select op from Operator op where lower(op.key) = lower(:operator)) MEMBER OF contentEntry.operators))
答案 0 :(得分:0)
我不确定这个查询到底出了什么问题,但我建议你以简单的形式重写它,也许会有所帮助:
SELECT DISTINCT NEW MAP (ce.content AS content, ce.id AS record_id)
FROM EntertainmentContentBean ce LEFT JOIN ce.operators op
WHERE op IS NULL OR lower(op.key) = lower(:operator)
答案 1 :(得分:0)
我最终使用子查询来获得所需的结果。