Reputation: 62394
My Database:
WorkflowProcess
id | name
WorkflowProcessToWorkflowProcess
ancestor | descendent
I need to query for root WorkflowProcess
. With this table structure, I'm looking to query something like SELECT * FROM WorkflowProcess WHERE id NOT IN (SELECT DISTINCT descendent FROM WorkflowProcessToWorkflowProcess)
My WorkflowProcess
entity:
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;
}
Is it possible to accomplish this with HQL?
Upvotes: 0
Views: 213
Reputation: 242696
Try something like this:
select child
from WorkflowProcess parent right join parent.workflowProcesses child
where parent is null
Upvotes: 1