Skip to content
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

Do not store mapping field in Configuration #3398

Merged
merged 16 commits into from
Aug 15, 2023

Conversation

hazzik
Copy link
Member

@hazzik hazzik commented Aug 6, 2023

Fixes #3397.

(Actually patched with minimal changes in 5.3x with #3399, then fixed more robustly here.)

Assert.That(mapping, Is.Not.Null, "Unable to find mapping object");
return mapping;
}
private static IMapping GetMapping(Configuration cfg) => (IMapping) cfg.BuildSessionFactory();
Copy link
Member Author

Choose a reason for hiding this comment

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

The true equivalent for the original code in the new way would be GetMapping(Configuration cfg) => cfg.BuildMapping(), but Dialect would throw an InvalidOperationException. However, in this case it does not matter and we can use fully resolved session factory instead.

Copy link
Member

Choose a reason for hiding this comment

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

Now new public "BuildMapping" can be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking about it and don't like it. cfg.BuildMapping just should not exist as it provides an incomplete version of mapping, that can create a lot of problems.

Copy link
Member

@bahusoid bahusoid Aug 15, 2023

Choose a reason for hiding this comment

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

nit: I don't understand your concern. In my understanding IMapping was specifically designed to be safely used in "uncompiled" state. See interface description:

/// Defines operations common to "compiled" mappings (ie. <c>SessionFactory</c>) and
/// "uncompiled" mappings (ie <c>Configuration</c> that are used by implementors of <c>IType</c>

So as long you use interface methods and don't do some funny castings you should be safe.

You agreed to keep method public - so it would be good to have it in tests too.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think the IMapping was designed. It was probably appeared incidentally from some other bad design decision. Problem with the interface that it is not clear when it is safe to use compiled or raw mappings. For example, SingleTableEntityPersister accepts both IMapping and ISessionFactoryImplementor. Can it use only ISessionFactoryImplementor?

public SingleTableEntityPersister(PersistentClass persistentClass, ICacheConcurrencyStrategy cache,
ISessionFactoryImplementor factory, IMapping mapping)
: base(persistentClass, cache, factory)

This is really not clear.

Also, Hibernate has removed this interface and redesigned the mapping compilation.

@bahusoid

This comment was marked as resolved.

@hazzik hazzik changed the title Do not store mapping in Configuration Do not store mapping field in Configuration Aug 7, 2023
Assert.That(mapping, Is.Not.Null, "Unable to find mapping object");
return mapping;
}
private static IMapping GetMapping(Configuration cfg) => (IMapping) cfg.BuildSessionFactory();
Copy link
Member

Choose a reason for hiding this comment

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

Now new public "BuildMapping" can be used.

src/NHibernate/Cfg/Configuration.cs Outdated Show resolved Hide resolved
@hazzik hazzik enabled auto-merge (squash) August 15, 2023 08:13
@hazzik hazzik disabled auto-merge August 15, 2023 08:13
@hazzik hazzik merged commit 509ed76 into nhibernate:master Aug 15, 2023
18 checks passed
@hazzik hazzik deleted the refactor-cfg branch August 15, 2023 14:57
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.

GenerateSchemaCreationScript creates many identical dialect instances
3 participants