You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There was a previous fix to queries for entites that use the "not-found='ignore'" mapping that worked prior to 5.3. That fixed an issue when there was a single null check, but there are still some other edge cases that aren't being handled correctly.
The first is when querying for null or another entity. For example, giving two entities:
public class Human
{
public virtual int Id { get; protected set; }
public virtual string Name { get; set; }
}
public class Dog
{
public virtual int Id { get; protected set; }
public virtual string Name { get; set; }
}
Giving the mapping
public class DogMap : ClassMap<Dog>
{
public DogMap()
{
Id(x => x.Id);
Map(x => x.Name)
.Length(16)
.Not.Nullable();
References(x => x.Human)
.NotFound.Ignore();
}
}
Only one dog with the human that still exists will show up due to an implicit comma join:
select
dog0_.Name as col_0_0_
from
"Dog" dog0_
left outer join
"Human" human1_ on dog0_.Human_id=human1_.Id,
"Human" human2_
where
dog0_.Human_id=human2_.Id and (human1_.Id is null or human2_.Id=@p0);
@p0 = 2 [Type: Int32 (0:0:0)]
The second issue is when you try and query for the deleted id directly:
This used to bring back dogs whose owner is the now deleted Joe. This seems to also be due to the implicit comma join
select
dog0_.Name as col_0_0_
from
"Dog" dog0_,
"Human" human1_
where
dog0_.Human_id=human1_.Id and human1_.Id=@p0;
@p0 = 1 [Type: Int32 (0:0:0)]
Interestingly enough, after Joe has been removed, and you remove the NotFound.Ignore property on the dog mapping, then the query using Joe's old id works. This seems like it may be a workaround if you don't need to delete new entities.
I've attached a minimal working example using NHibernate 5.3.10 and FluentNhibernate that demonstrates these issues NHibernateTest.zip
The text was updated successfully, but these errors were encountered:
The second issue is when you try and query for the deleted id directly:
First issue should be fixed by #2989. And the second issue - current behavior looks correct to me. As you directly instructed to ignore not found records so they are treated as NULL also in queries and only query by valid ID or by NULL can be found.
fredericDelaporte
changed the title
More query issues when using not-found='ignore' in entity mapping
Query issues when using not-found='ignore' in entity mapping
Feb 17, 2022
There was a previous fix to queries for entites that use the "not-found='ignore'" mapping that worked prior to 5.3. That fixed an issue when there was a single null check, but there are still some other edge cases that aren't being handled correctly.
The first is when querying for null or another entity. For example, giving two entities:
Giving the mapping
And data:
and we query
Only one dog with the human that still exists will show up due to an implicit comma join:
The second issue is when you try and query for the deleted id directly:
This used to bring back dogs whose owner is the now deleted Joe. This seems to also be due to the implicit comma join
Interestingly enough, after Joe has been removed, and you remove the NotFound.Ignore property on the dog mapping, then the query using Joe's old id works. This seems like it may be a workaround if you don't need to delete new entities.
I've attached a minimal working example using NHibernate 5.3.10 and FluentNhibernate that demonstrates these issues
NHibernateTest.zip
The text was updated successfully, but these errors were encountered: