nhibernate-core icon indicating copy to clipboard operation
nhibernate-core copied to clipboard

WIP Cascade entities loaded during flush

Open bahusoid opened this issue 5 years ago • 9 comments

This change allows to properly flush and cascade entities that were loaded and modified during flush (I know this is not recommended way of doing things but sometime it can be useful)

Fixes #1252

bahusoid avatar Apr 05 '19 12:04 bahusoid

This is extremely weird use case. I spent too much time trying to understand what's going on.

hazzik avatar Jun 17 '19 05:06 hazzik

Yeah. I agree test case from #1252 is very weird. But in general this PR covers condition when entity is modified on loading event and this loading happens during flush for whatever reasons (non lazy association or something like that)

In test case it's not even loading it's proxy creation.

bahusoid avatar Jun 17 '19 05:06 bahusoid

This is what it takes to make the test green (90ea46768ce5a3748005a64dc6b97f5f3c89f643):

https://github.com/nhibernate/nhibernate-core/blob/90ea46768ce5a3748005a64dc6b97f5f3c89f643/src/NHibernate.Test/NHSpecificTest/NH2919/Child.cs#L9-L13

hazzik avatar Jun 17 '19 05:06 hazzik

The culprit is access="readonly". This so called "feature" should have never been implemented.

hazzik avatar Jun 17 '19 05:06 hazzik

The test becomes green when either:

  • DynamicToy is set using the property
  • DynamicToy does not have access="readonly"

hazzik avatar Jun 17 '19 06:06 hazzik

The test becomes green when either: DynamicToy is set using the property

That's because of stupid logic inside property setter. Yeah test is strange and I should have come up with something more simpler and clear instead of reusing it. But again the issue should be clear: entity is loaded and modified during flush. Cascade changes won't be applied for such entities. If you have some complex checks in interceptor - it's quite possible scenario (I've personally investigated it in some legacy app).

I will try to add some simple test demonstrating this behavior as I agree current test is hard to understand

bahusoid avatar Jun 17 '19 08:06 bahusoid

Actually I can't come up with anything that looks sane :) Maybe such scenarios are indeed should be considered too specific to be handled in nhibernate. So feel free to close this PR...

bahusoid avatar Jun 17 '19 09:06 bahusoid

DynamicToy does not have access="readonly"

This still holds.

hazzik avatar Jun 17 '19 12:06 hazzik

These tests need a sensible asserts at least. They currently do not check anything (except implicit check for TransientObjectException).

hazzik avatar Jun 17 '19 12:06 hazzik