-
Notifications
You must be signed in to change notification settings - Fork 934
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
Can not use joined-subclass of xml mapping to extend the mappings build with NHibernate.Mapping.ByCode #2307
Comments
After debug and check the source code of NHibernate.Cfg.Configuration, there is an internal validation queue to process the mappings added by xml, but no way to skip it. So the simple work around is converting the var mapper = new ModelMapper();
mapper.AddMapping<IdentityRoleMappingPostgreSql>();
// add other mapping here.
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
// Use AddXml instead of AddMappings
cfg.AddXml(mapping.AsString()); |
I do not know if mixing hbm and By-Code mappings is an "accidental" feature or if it is supposed to work flawlessly in any cases. So I do not really know if the trouble your report should be qualified as a bug or as a feature request. For now I settle on feature request. |
I think it should be a feature too. Maybe we should provide an optional parameter for mapping by xml, let users to specify explicited root entity, provide similar function like the |
I've just run into this and I can provide a very good (at least IMO) reason why this scenario should be supported. That's because of issue #1277, for which the workaround is essentially "Use an FWIW, the workaround @beginor described (convert the MbC mappings to XML & import as XML, then add |
I have noticed that the workaround: using MBC, then convert those mappings to XML and add them that way, is somewhat less viable from NHibernate 5.4.1 onward. That's if those mappings contain any one-to-one relationships, because of a new crash bug adding the mappings. See #3607 for more information. |
I am refacting the mapping of NHibernate.AspNetCore.Identity to
NHibernate.Mapping.ByCode
, as descripted in the issue nhibernate/NHibernate.AspNetCore.Identity#16 .I have rewrite the orignal xml mapping of
NHibernate.AspNetCore.Identity
withClassMapping<T>
, the code looks like this:The full mapping code is here:
https://github.com/nhibernate/NHibernate.AspNetCore.Identity/tree/master/src/NHibernate.AspNetCore.Identity/Entities
Then I try to extend these mappings with
joined-sublcass
of xml mapping, like this:I got the following exception when setting up nhibernate:
Then I rewrite the xml mapping with
JoinedSubclassMapping<AppRole>
, which works , can build session factory and query without any exception.So the issue is:
JoinedSubclassMapping<T>
to extend the mappings build withClassMapping<T>
, it works _01_CanExtendByCodeWithByCode;joined-subclass
of xml mapping to extend the mappings build withClassMapping<T>
, get an exception ofNHibernate.MappingException : These classes referenced by 'extends' were not found
_02_CanExtendByCodeWithXml;joined-subclass
xml mapping to extendclass
xml mapping, it works _03_CanExtendXmlByXml;JoinedSubclassMapping<AppRole>
to extendclass
mapping of xml, it works _04_CanExtendXmlByByCode;The full test code is here: https://github.com/nhibernate/NHibernate.AspNetCore.Identity/blob/master/test/UnitTest/IdentityTest.cs
Maybe there something I do wrong, or some issues with nhibernate's mappings?
The text was updated successfully, but these errors were encountered: