ICriteria/QueryOver create incorrect left join condition when table-per-hierarchy is used with filters

Description

Querying using ICriteria or QueryOver creates joins with conditions in the main WHERE clause instead of the JOIN clause.

This breaks left joins when using table-per-hierarchy discriminators as the condition in the WHERE clause effectively turns the left join into an inner join.

This bug only appears when any filter is enabled, whether the filter is used or not.

It also does not appear to affect queries written in HQL.

This mapping demonstrates the problem:

Querying using this HQL query works fine:

select e from Employee e left join e.Department d

This QueryOver query fails:

SQL generated for HQL query:

A test case will follow shortly.

I have also provided a patch containing a fix that appears to solve this issue. All unit tests still pass after this fix.

Environment

None

Attachments

2

Activity

Alex Zaytsev November 25, 2018 at 8:57 PM

Moved here.

Radim.Kohler July 9, 2015 at 2:37 PM

Please, are there any plans to apply that patch? Seems to be working. And the issue without fix still remains? Any comments?
Thanks
Radim Köhler

Stefan Blaha March 11, 2015 at 9:28 AM

Thanks, got it. We do have filter on the session to filter out "deleted" entities, and we don't really want to disable this since then the behavior will change so I guess going with ugly use-query-only-when-left-joining alternative is the way to go.

Patrick Froede March 11, 2015 at 8:56 AM

Disabling filters on many-to-one by setting use-many-to-one to false on the filter-def worked in my case.

This was fine for us as we didn't actually want the filters applying in a many-to-one scenarios.

The bit would still like changed is that enabling any filter affects discriminators in an unexpected way even if the filters do not apply to the class.

Stefan Blaha March 11, 2015 at 8:42 AM

We have the same issue where a "References" association used in a left join in a table-per-hiearchy design causes the discriminator value to be used in the global where thus resulting in no rows if the left join does not produce any rows.

The only workaround I see is creating query only property that, instead of referencing the concrete type, references the common base type and then manually insert the discriminator as a restriction in the left join itself.
Am I missing something or is there a better workaround for above scenario?

Fixed

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created August 5, 2013 at 2:43 PM
Updated September 19, 2019 at 11:40 AM
Resolved November 25, 2018 at 8:56 PM
Who's Looking?