My Entity mapping is as follows:
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;
}
.
.
.
}
I’ve a specific requirement where I want to retrieve EntertainmentContentBean records based on following criteria:
- If no operator records are present
- If operator records are present, then operator list should contain the operator object passed are the parameter
I tried following query but it is not returning expected records:
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))
I ended up using subquery to get the desired results.