-
Notifications
You must be signed in to change notification settings - Fork 936
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 SQL when referencing nullable entity in correlated subquery #3306
Comments
Likely a regression from #2989. |
I tried to put your test case to the code and I think you have some invalid data in the script:
|
Good spot @hazzik - I put the a value in the wrong place. I'll fix it in that repo in a few mins. Edit: That data fix is done! |
I was also looking for converting it into our test case, but stopped when I had to check whether foreign key constraint violations were due to voluntarily invalid data (since the mapping uses Here is the commit with this point not handled: c6efeb8 |
Hi @fredericDelaporte - the database in our real app is unfortunate in this case. I'd love to burn that schema to the ground but I am forced to retain backwards compatibility with a suite of legacy apps. The only voluntarily/intentionally missing data in that data set is the The others should relate to rows in the |
Your current insert script is:
l_entity 3 looks invalid too. u_entity 2 is linked with p_id 1, so a l_entity linked to u_id 2 cannot be linked to p_id 2. If l_entity 3 has to be valid, either its insert has to change, or u_entity 2 has to be linked to p_id 2. |
No need to bother with data consistency. I think I know what's going on and simply adjust existing unit test. |
Sorry guys, the sample data was an afterthought, because the main nature of the problem was generation of invalid SQL. The DB was rejecting the query regardless of data. The intent was to provide some data which should return one row, assuming that the |
Fixed by #3312 |
You can try the fix with the 5.3.17.dev build on Cloudsmith. Also see Nightly builds. |
We have recently tried upgrading NHibernate for our private project and found that the upgrade caused crashes against some particular queries that had previously returned the expected results.
I have narrowed this problem down to having been introduced in NHibernate 5.3.11 (last working version was 5.3.10). I have also created a standalone reproduction project, which I have placed online. I have tried to keep the example as minimal as possible, to match the query & techniques that we are actually using. Some of the query/mappings/entities might prove to be irrelevant though.
Full repro steps and the analysis I have already performed are available in the Readme to that repo. You'll also find a sample schema creation script in there. It also includes copies of the SQL produced by 5.3.10 and 5.3.11 and an indication of where they differ. In short, in a multi-table subquery which NHibernate creates, it omits a comma between two tables in the FROM part of the query. This then causes a crash error because the DB rejects it.
There is another difference in the SQL though, which might prove to be another problem entirely (I'm happy to open a new ticket if someone determines that it is indeed unrelated). The criterion which uses the formula for a
many-to-one
association (which is mapped using a formula) is omitted from the WHERE from 5.3.11 onward. I think that even if the invalid SQL (missing comma) issue were fixed, the query would still return incorrect results because of the omitted criterion.I have reproduced this with T-SQL (MS SQL Server) but I have not tried it with other database drivers/dialects such as SQLite. It may or may not affect those too. I have also reproduced it with the current latest NH version (at time of writing) 5.4.2.
The text was updated successfully, but these errors were encountered: