-
Notifications
You must be signed in to change notification settings - Fork 930
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
Invalid ByCode serialization to XML for OneToOne mappings #3607
Comments
So, #3216 somewhat looks as the possible root of the trouble. But looking at it, the reason for introducing #3216 was:
In other words, your mapping was using an unsupported property which was simply ignored. But it has been supported in 5.4.1, seemingly not correctly for by code mappings serialization. |
Thanks @fredericDelaporte. In fact we hadn't been using optimistic lock in our MBC mapping. When the bug repros, even if the MBC mapping doesn't mention optimistic lock, it still attempts to serialize the property into XML. Presumably the process serializes the whole MBC object graph to XML, including properties which are at their default values, which could technically be safely omitted from the XML. |
Fixed by #3613. Dev builds for 5.4.10 should be available in a few hours. |
Hi @fredericDelaporte - are you sure you linked the right PR? I was curious and glanced at #3610, but it doesn't seem to relate to mapping at all. It's only about the GUID COMB generation algorithm 😕 Ah, I see now, I think you meant #3613. It's linked correctly above. |
We've come across this issue today whilst upgrading from 5.3.7 to the latest version (5.5.2 at time of writing). It's a crash error when using code like the following, if those mappings included any one-to-one relationships between entities. The conversion-to-XML process appears to generate invalid XML which then crashes during XML schema validation.
Importantly, this affects the viability of the (AFAIK) only known workaround to #2307, which we are using.
I've created a minimal self-contained reproduction case, hosted at this repository. I'll also reproduce the README for that repo below, as that contains a little more analysis.
Reproduction case for an NHibernate crash issue when converting Mapping By Code (MBC) mappings into XML, when those MBC mappings include any One to one mappings.
The
optimistic-lock
element/attribute is incorrectly serialized to XML and subsequently causes an XML schema validation error.Versions affected
I tried this out against a variety of NHibernate versions.
So, it would certainly seem that 5.4.1 is the first affected version.
Sample reproduction case
There are two unit tests in the test project. One demonstrates the behavior using 'pure MBC' and the other uses the 'convert MBC mappings to XML' technique.
The remainder of the project is a minimal NHibernate entity & mapping setup with 3 entities, mappings and a small helper to create a session factory for them.
It uses SQLite in-memory driver/dialect so as to be self-contained.
As far as I can tell the DB driver/dialect is irrelevant though, because we reproduced this in an MS SQL Server environment.
dotnet build
dotnet test
NhVersion
property to the desired NHibernate versiondotnet test /p:NhVersion=5.4.9
Expected behaviour
The tests for both techniques should pass (should not throw an exception).
Actual behaviour
The 'pure MBC' test passes, but the test for the technique which converts to XML fails with an exception:
Related info
This affects the viability of a workaround for another NHibernate bug; issue 2307 on the NHibernate issue tracker.
That workaround to issue 2307 (which affects the capabilities of MBC mappings) is to use the 'convert MBC mappings to XML' technique.
That workaround is no longer viable for mappings which include any one to one relationships, because that would now cause a crash error.
The text was updated successfully, but these errors were encountered: