我的数据库:
WorkflowProcess
id | name
WorkflowProcessToWorkflowProcess
ancestor | descendent
我需要查询根WorkflowProcess
。使用此表结构,我希望查询类似SELECT * FROM WorkflowProcess WHERE id NOT IN (SELECT DISTINCT descendent FROM WorkflowProcessToWorkflowProcess)
我的WorkflowProcess
实体:
private Collection<WorkflowProcessEntity> workflowProcesses;
@JoinTable(name = "Workflow_Process_to_Workflow_Process", joinColumns = {
@JoinColumn(name = "ancestor", referencedColumnName = "id")}, inverseJoinColumns = {
@JoinColumn(name = "descendent", referencedColumnName = "id")})
@ManyToMany()
public Collection<WorkflowProcessEntity> getWorkflowProcesses() {
return workflowProcesses;
}
public void setWorkflowProcesses(Collection<WorkflowProcessEntity> workflowProcesses) {
this.workflowProcesses = workflowProcesses;
}
是否可以使用HQL实现此目的?
答案 0 :(得分:1)
尝试这样的事情:
select child
from WorkflowProcess parent right join parent.workflowProcesses child
where parent is null