-
Notifications
You must be signed in to change notification settings - Fork 934
Force join for comparisons in hql when not null entity key can represent null entity #2081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force join for comparisons in hql when not null entity key can represent null entity #2081
Conversation
b849b26
to
e84c87f
Compare
Force pushed to resolve conflicts. The fixup commit got squashed. |
e84c87f
to
0463dae
Compare
Can we get this reviewed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree for fixing the one-to-one non constrained case, where the foreign-key is (in true one-to-one cases) also the primary key and can never be null as such, and the the other side uses the foreign
id generator, borrowing its primary key from the non-constrained entity.
But I disagree for the not-found
ignore case, because it is detrimental for the general use-case, which is not to use this feature mainly meant for legacy DB with corrupted data. (Hibernate does not have this feature by the way, it is a NHibernate specific addition. I am not sure it is a good legacy to have added it.)
Adding joins for the general case, where foreign key are actual foreign keys, where a not-null foreign key can only mean the other side exists, is a bad move I think. So I think this PR should be adjusted to perform this change only for the one-to-one non-constrained case, and eventually for the case where a not-found
ignore is detected.
Just to be clear
nhibernate-core/src/NHibernate/Type/EntityType.cs Lines 294 to 298 in 3d92bf4
Offtopic: It's strange I didn't get notification for your review. Just noticed accidentally that PR was recently updated. |
…ent null entity (nhibernate#2081) Co-authored-by: Alexander Zaytsev <hazzik@gmail.com>
Fixes #1274 (criteria is not fixed, but criteria doesn't support implicit joins. So in criteria it's up to user to properly create joins for such associations)
Add force join for associations with
EntityType.IsNullable == true
(like not constrained one-to-one or associations with not-found="ignore" mapping):nhibernate-core/src/NHibernate/Type/EntityType.cs
Lines 294 to 298 in 3d92bf4
So when such property is used in comparisons like
where alias.OneToOne is null
we must add join and do comparison with joined table.