0

我的数据库:

WorkflowProcess
id | name

WorkflowProcessToWorkflowProcess
ancestor | descendent

我需要查询 root 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 来完成此任务?

4

1 回答 1

1

尝试这样的事情:

select child 
from WorkflowProcess parent right join parent.workflowProcesses child 
where parent is null
于 2013-04-11T12:41:04.503 回答