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

NHibernate.Extensions.Logging causes NHibernate to work incorrectly #83

Closed
robsosno opened this issue Jan 14, 2023 · 2 comments
Closed

Comments

@robsosno
Copy link

Describe the bug
I've recently upgraded my application from .NET 3.1 to 6.0. Version of NHibernate was not changed - it was 5.2.5.0.
I've change also logging method. Previously NHibernate was logging to Common.Logging via NHibernate.Logging. After upgrade I've installed and configured NHibernate.Extensions.Logging
Simple tests confirmed that change was successfully implemented.
However after some time we've found that queries contained join work incorrectly. For JoinEntityAlias method (as in screenshot) we've got incorrect syntax - part of where statement was put into the from clause. Message was "could not execute query".
I've converted JoinEntityAlias into proper Linq query. Then we've obtained message "undefined join type".
We have other types of specyfying joins but I haven't tested it.
After removing Nuget package with NEL everything was back to normal.
I've recompiled NEL from sources referencing our local copy of NHibernate.dll and then used this instead of oryginal NEL NuGet package. Everything behaves as expected.

To Reproduce
Steps to reproduce the behavior:
Install NHibernate version 5.2.5.0 . Create a query with JoinEntityAlias.
Then install NHibernate.Extensions.Logging version 2.3.1 Nuget.
Add
var loggerFactory = app.ApplicationServices.GetRequiredService<Microsoft.Extensions.Logging.ILoggerFactory>();
NHibernateLogger.SetLoggersFactory(new MicrosoftLoggerFactory(loggerFactory));
in Configure method in Startup class.
Query will not run as before.

Expected behavior
Logging should never change application behavior. Especially it should not change generated queries.

Screenshots
image002

Additional context
Add any other context about the problem here.

@akunzai
Copy link
Owner

akunzai commented Jan 14, 2023

Hi @robsosno,

I'm doubt the NHibernate.Extensions.Logging can change NHIbernate behavior, it just a logger adapter for NHibernate.

I guess this may caused by different NHiberate version bewteen 5.2.5(your app uses) and NHibernate 5.3.11 (NHibernate.Extensions.Logging 2.3.1 uses).

The NHibernate.Extensions.Logging 2.3.3 downgrade NHibernate to 5.2.0

Can you confirm if the latest release solves your problem?

@robsosno
Copy link
Author

I also could not believe in this. But confirmation was simple - by adding/removing NuGet I got error or not. Fully repeatable.
I cannot imagine what mechanism would affect NHibernate to generates queries differently.

I've just tested that version 2.3.3 works for me.

I've reverted to NEL 2.3.1. it appears that build folder contains NHibernate.dll version 5.3.11.0 .
I had my NH 5.2 library taken from local libs folder and NEL from NuGet. Probably NEL took another NH from net and overridden local version.
So my code was compiled with 5.2 and run with 5.3 and this is the source of problems.
I should have NHibernate from Nuget. Probably then NHibernate library would not be overridden.
There is no particular reason to not have NH from NuGet. It is just because project was started long ago.
Anyway it was very surprising behavior.

I do not know if reverting to NH 5.2 with NEL 2.3.1 is good decision. In 2.3.1 you've specified that it is targeted for NH 2.3+. So it appears that I've made a mistake.
The only thing we can do is to describe consequences if preconditions are not fulfilled. And this thread is just that.

@akunzai akunzai closed this as completed Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants