In essence, what I mean is that any related entity** - be it a many-to-one,
one-to-many or some other kind of relation - should ideally be included in
the query using a derived table *if it has a <join>*. It is, however,
unnecessary to do that for the "core" entity queried, and it should be
avoided.

select [same stuff here]
from A a
inner join APrime ap on a.Id=ap.Id
left outer join (select .... from b inner join BPrime bp on b.Id=bp.Id) db
on A.Id = db.Id

But not

select [same stuff here]
from (select ..... from A a
inner join APrime ap on a.Id=ap.Id) da
left outer join (select .... from b inner join BPrime bp on b.Id=bp.Id) db
on da.Id = db.Id

In TSQL, the objective could be accomplished with CTE:s as well, but I doubt
that it's feasible to do that in NH.

/G

2011/10/5 Isaac Cambron <[email protected]>

> Thanks for all the feedback!  I think I'm OK on the process part of
> submitting a patch, (e.g. I have a pull request for a different issue in the
> submission queue).
>
> On the technical merits, I think I should be able to provide a convincing
> test that the current behavior isn't compatible with the spec. E.g. in the
> example from the Jira issue, if a BPrime row wasn't in the database, its
> corresponding B shouldn't come back in that query, either.
>
> I'm not sure I understood Gunnar's point:
>
> >However, if the use of derived tables is restricted to related entities,
> it will comply with the docs and still behave more properly.
>
> What do you mean by related entities here? I'm thinking the spec really
> wants the inner join:
>
> If set to join, the default, Hibernate will use an inner join to retrieve
> a <join> defined by a class or its superclasses and an outer join for a
> <join> defined by a subclass.
>
> Certainly, I need to only use a derived table when BPrime is defined on B
> and not one of B's subclasses. Also, only when optional=false. But am I
> missing something more?
>
> Thanks,
> Isaac
>
> On Tue, Oct 4, 2011 at 5:36 AM, Richard Brown (gmail) <
> [email protected]> wrote:
>
>>
>> >  3. Any pointers one where I should start? I know my way around the code
>> base a little bit, but if anyone has some advice on how to attack this
>> issue, I'd appreciate it.
>>
>> Start with a failing test ... that alone could be pulled/cherry-picked
>> into the master branch (and flagged as [Ignore] until it is implemented.)
>>
>>
>>
>
>

Reply via email to