是否可以使用HQL查询连接表?

时间:2013-04-11 12:36:50

标签: spring hibernate hql

我的数据库:

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实现此目的?

1 个答案:

答案 0 :(得分:1)

尝试这样的事情:

select child 
from WorkflowProcess parent right join parent.workflowProcesses child 
where parent is null