Bug 402 : disjunction expression should not produce inner join - left outer join instead
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
github
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
28/05/2012
Updated 
28/05/2012
Type 
Bug
 
Attachments 
No attachments

Hello,

I have ScheduledAssignment such that it has a foreign key to itself. IOW with "linked" instances A, B, C of ScheduledAssignment:

A_B_C

B and C have "parentScheduledAssignment" of A (a foreign key).

This simple query attempts to pull in the other related objects, so given B I should get [A, C] and given A I should get [B, C]:

query.where()
.disjunction()
.eq("parentScheduledAssignment", scheduledAssignment) // SA is child of this one
.eq("childScheduledAssignments.id", scheduledAssignment.getId()) // or parent of this one
.endJunction()
.ne(ScheduledAssignment.pId, scheduledAssignment.getId()) // not this one
.findList();


But this is the SQL produced:

select distinct [a bunch of stuff]
from public.scheduledassignments t0
join public.scheduledassignments u1 on u1.parentscheduledassignmentid = t0.scheduledassignmentid
where (
t0.parentscheduledassignmentid = ?
or u1.scheduledassignmentid = ?
)
and t0.scheduledassignmentid <> ?

Notice the regular join u1. The result is an empty list.

The relevant part of ScheduledAssignment:

@Entity
@Table(name = "scheduledassignments", schema = "public")
public class ScheduledAssignment {

@Id
@Column(name = "scheduledassignmentid")
private Integer id;
@ManyToOne
@JoinColumn(name = "parentscheduledassignment")
private ScheduledAssignment parentScheduledAssignment;
@OneToMany(mappedBy = "parentScheduledAssignment")
private List childScheduledAssignments;
}

Shouldn't Ebean produce a left join for parentScheduledAssignment? If I remove the where criteria and "fetch" parentScheduledAssignment properties it does in fact produce a left join. This seems a pretty common scenario. How do I solve this?

 
Rob 28 May 03:08
Above from google group

Above comment from Daryl. Yes I agree, being a disjunction ... an outer join should be used (not inner join) in this case.

gbsmith 05 Sep 14:07
Updates?

Any progress on this bug?

woResponse

Upload a file