I habe Entity Report with "CollectionTable" ReportUser:
@Entity class Report {
@Column private Short userId;
@Column(name = "reportUserId") @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "ReportUser", joinColumns = { @JoinColumn(name = "reportId", referencedColumnName = "reportId") }) private Set reportUsers = new HashSet<>();
}
I need to write following SQL using CriteraiQuery (basically I need all reports that are either created by user 1111 or userId 1111 is in that collection table:
select * from Report r join ReportUser ru on r.reportId = ru.reportId where r.userId=1111 or ru.reportUserId=1111;
Any idea how to to that?
Thank you and best regards Dalibor