我有以下课程:
@Entity
@Table(name = "entity")
public class Entity extends Model
{
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "entity_owner", joinColumns = @JoinColumn(name = "entity_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
private Set<UserAccount> owners;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "entity_assignee", joinColumns = @JoinColumn(name = "entity_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
private Set<UserAccount> assignees;
}
我有一个用户帐户,我希望能够返回在所有者或受让人中拥有用户的所有实体对象。
我试过这个,它几乎可以工作,但似乎回到了某种笛卡尔结果:
String query = "SELECT r FROM models.Entity r LEFT JOIN r.assignees a LEFT JOIN r.owners n ";
query += "WHERE a.id = 1 OR n.id = 1";
谁能告诉我我做错了什么?