Bug 417 : Inheritance with nullable relationship produces incorrect SQL
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
3.x
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
29/07/2012
Updated 
29/07/2012
Type 
Bug
 
Attachments 
No attachments

Hello,

I have a subclass Case of an AbstractCase defined like so:

@Entity
@DiscriminatorValue(value = "1")
public class Case extends AbstractCase {
@ManyToOne
@JoinColumn(name = "parentcaseid")
Block block; // discriminator "2"
...
}

A query like this:
Query query = Ebean.find(Case.class).where()...

produces SQL like this:
select t0.abstractcasetype as c0, t0.caseid as c1 ..., t2.abstractcasetype as c18, t2.caseid as c19
from public.cases t0
left outer join public.cases t2 on t2.caseid = t0.parentcaseid
where t0.abstractcasetype = '1' and t2.abstractcasetype = '2' ...

Since Case.block is nullable, the left join is proper, but the discriminator test in the where phrase filters out all Cases where the block is null. It seems the where phrase should be something like:
where t0.abstractcasetype = '1' and (t2.abstractcasetype = '2' or t2.caseid is null)

I can get around this problem by turning off auto fetch and selecting what I need.

 
Ariel Scarpinelli 26 Sep 14:52
Duplicates bug #408

Daryl Stultz 12 Dec 21:13
Workaround not always possible

The workaround I mentioned works for queries, but not for find:

Ebean.find(MyBean.class, 1234)

since there is no control over the query. This elevates the severity of this bug for me.

woResponse

Upload a file