Skip to content

Bidirectional list fails if session only knows about child #2089

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 3 commits into from
Jun 20, 2019

Conversation

RogerKratz
Copy link
Contributor

When having a bidirectional inversed list, child seems to not fully "own" the collectionref when using session.Merge on child.

When running failing test, child will end up with order index -1 in db because when nhib's merge occur, the child is "unhooked" from its parent.

Probably closely related to #1531.

@bahusoid

This comment has been minimized.

@RogerKratz

This comment has been minimized.

@bahusoid

This comment has been minimized.

@RogerKratz
Copy link
Contributor Author

I meant owner/non-owner related logic is applied only for collection.

Sure, I'm not talking about cascading or similar. Still, it's a bidirectional reference, and child know it's parent (and orderindex) in the domain model, so why shouldn't it be possible to save child without session knowing about parent, if that's what you mean?

(Even with inverse=false it should work, but that's seldom/never used if ref is bidirectional I think?)

@RogerKratz RogerKratz changed the title Inverse list fails if session only knows about child Bidirectional list fails if session only knows about child Mar 27, 2019
@RogerKratz

This comment has been minimized.

@bahusoid
Copy link
Member

bahusoid commented Mar 27, 2019

and child know it's parent

Child knows only what's in its mapping. So it knows Parent but knows nothing that Parent has Children. Merge only processes supplied entity and associations according to cascade settings. You have no cascade settings specified for Parent. So why do you expect it to be saved as part of Parent.Children collection?

@RogerKratz
Copy link
Contributor Author

RogerKratz commented Mar 27, 2019

Child knows only what's in its mapping. So it knows Parent but knows nothing that Parent has Children. Merge only processes supplied entity and associations according to cascade settings. You have no cascade settings specified for Parent.

Agreed.

So why do you expect it to be saved as part of Parent.Childrencollection?

I don't. Why do you think I expect that? ;) We must be misunderstanding each other...
I expect "newChild" (not its parent) to be correctly persisted in the test.

@bahusoid

This comment has been minimized.

@RogerKratz
Copy link
Contributor Author

RogerKratz commented Mar 27, 2019

Actually I dont. I expect Child's OrderIndex property and mapping to be used.
Yes, the implementation of that property traverse the domain model (in this case to the parent). But from nhib's perspective (and the mapping), it should be irrelevant. It's just references in ram so to speak. And the refs "work" when Merge is called.

@bahusoid

This comment has been minimized.

@RogerKratz
Copy link
Contributor Author

@bahusoid Thanks for your time and discussion. Glad I could finally make myself a bit clearer :)

@hazzik
Copy link
Member

hazzik commented Apr 26, 2019

According to this: https://stackoverflow.com/a/1758311/259946 bi-directional inverse list does not work at all. As I can see you have implemented a hack similar to the hack described in the SO answer.

The NH-1338 has been closed as not an issue with weird explanation.

Issues on hibernate's JIRA (HB-79, HHH-1165, HHH-3425) are also closed with the same explanation.

(Here I'm really talking to myself trying to make sense of the mapping)

@RogerKratz
Copy link
Contributor Author

RogerKratz commented Apr 26, 2019

@hazzik IIRC, "bi-directional inverse list does not work at all" was true a couple of years ago. Nowadays it is/should be supported as of 6.3.3 in documentation. Unfortunately, domain model is not part of those examples.

The problem (if it is?) is probably the same as #1531. It only happens when merging entities. NHib then "detaches" the entities in the domain model from eachother and makes copies of the data. Due to this the references themself inside the model no longer points to the "correct" entities and the hack (if it is?) no longer works.

@hazzik
Copy link
Member

hazzik commented Apr 29, 2019

I was talking about bidirectional inverse list without a special column.

@hazzik hazzik merged commit 03e5fa6 into nhibernate:master Jun 20, 2019
@hazzik hazzik added this to the 5.3 milestone Jun 20, 2019
@hazzik
Copy link
Member

hazzik commented Jun 20, 2019

Thanks. This has now lives on master. Not sure though if we're going to fix this.

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