Skip to content

Fix cascade + one-to-one failing on null no-proxy association #1720

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

Merged
merged 2 commits into from
Jun 3, 2018
Merged

Fix cascade + one-to-one failing on null no-proxy association #1720

merged 2 commits into from
Jun 3, 2018

Conversation

fubar-coder
Copy link
Contributor

@fubar-coder fubar-coder commented May 31, 2018

A unit test failure is expected, demonstrating #1719.

Copy link
Member

@fredericDelaporte fredericDelaporte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to let you know why an upcoming commit is going to alter the test.

/// if you prefer.
/// </remarks>
[TestFixture]
public class ByCodeFixture : TestCaseMappingByCode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to test for both mappings style, better remove one of them.

namespace NHibernate.Test.NHSpecificTest.GH1719
{
[TestFixture]
public class Fixture : BugTestCase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The async generator will generate an async counterpart for this test. Not generating it would cause some later generation to add it in an unrelated change, so it has to be generated. (Option H of showbuildmenu.bat, see contributing.)

@fredericDelaporte fredericDelaporte added this to the 5.2 milestone Jun 1, 2018
@fredericDelaporte
Copy link
Member

I have pushed a minimal fix, see commit details.

hazzik
hazzik previously approved these changes Jun 2, 2018
@fredericDelaporte
Copy link
Member

fredericDelaporte commented Jun 2, 2018

Something causes the test to fail for Oracle, going to check locally. (Update: a string column is set as not null but an entity attempt so set it with the empty string, which is handled as null by Oracle. So I am putting something in that string, this string being empty is irrelevant to the test.)

And well, rebasing for squashing things in two commits: the test then the fix.

I have not analyzed the Hibernate changes, which seems to have a broader purpose than just fixing the issue here.

I think the Hibernate change is also notably aiming at reducing the lazy loads triggered by cascades. Some are mandatory, by example when cascading a delete, other should be avoidable, by example when searching for orphans in order to handle delete-orphan.

fubar-coder and others added 2 commits June 2, 2018 19:24
This is a lightweight fix which does not change the no-proxy principles
at the root of the bug.
The no-proxy is currently implemented as a special case in the lazy
property interceptor, not flagged as a lazy property. Instead, on parent
entity load, it hides, in the parent loaded state for the no-proxy, a
proxy (!) flagged for unwrapping the associated entity it proxifies.
This hiden unwrapping proxy supports proxifying  non-existent entities.
The property interceptor does the unwrapping when accessing it. But when
the proxy unwraps to null, this causes the loaded state to have a
reference where it should be indeed null, causing dirty checking issues.

A better fix would be to flag the property as lazy for no-proxy
one-to-one associations, allowing to get in the loadedState the
"uninitializedProperty" instance, allowing the dirty checking mechanism
to know that this part of state is unknown (till loading it, at which
point it should be adjusted to its actual value).
But this causes the property interceptor to trigger initialization of
any other lazy properties when accessing a one-to-one. Avoiding this
would require to implement some lazy property fetch group semantic.

Fixes #1719

Co-authored-by: Alexander Zaytsev <hazzik@gmail.com>
@fredericDelaporte fredericDelaporte merged commit 25ad179 into nhibernate:master Jun 3, 2018
@hazzik hazzik changed the title Unit tests for issue #1719 Unit tests and fix for issue #1719 Jun 3, 2018
@hazzik hazzik changed the title Unit tests and fix for issue #1719 Fix cascade + one-to-one failing on null no-proxy association Jun 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants