NHibernate.ObjectNotFoundException: there is no row with the given identifier

Here is my mistake:

NHibernate.ObjectNotFoundException: No row with the given identifier exists[Project.Core.Entities.User#(GUID)] at Hibernate.Impl.SessionFactoryImpl.DefaultEntityNotFoundDelegate.HandleEntityNotFound(String entityName, Object id) at NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) 

One of the users of the system accidentally received this error, which makes no sense to me. What i know:

  • Teacher table. LINKS: User table.
  • Somehow, the Teacher table has a row that refers to a row in the User table, but this row does not exist in the User table.

Any idea why this is happening? Please advise!

Rephrase my Qn:

I know what the error means, however, it seems I don’t understand what caused the missing user line? I posted it all on Cascade.ALL. I do not think this is due to deletion. What are the possible scenarios that may occur above?

Edit 2:

Please refer to matching through FNH: Any problems with this?

 public void Override(AutoMapping<Teacher> mapping) { mapping.References(x => x.User).Cascade.All().Not.LazyLoad(); } 

Thanks!

+4
source share
5 answers

I set the Not Found property to Ignore

+4
source

In Fluent NHibernate for C #, I used

 HasManyToMany(x => x.Bars).Table("foobars") .ParentKeyColumn("FooId") .ChildKeyColumn("Id") .NotFound.Ignore(); 
+2
source

I assume that you missed the FK restriction in your database, otherwise you will not have any missing FK records. Add the FK and Cascade rules to your database, then you will not have any "missing row exceptions". When you try to do something that does not match your database model, an error will occur.

+1
source

Try it...

 public void Override(ModelMapper modelMapper) { modelMapper.Class<T>(c => { c.ManyToOne(m => m.FKObj, r => { r.Column("FKColumn"); r.NotFound(NotFoundMode.Ignore); // THIS IS IMPORTANT!!! }); }); } 

Or is it ... if you have an "Agreement" file ...

First handles the BeforeMapManyToOne event:

 mapper.BeforeMapManyToOne += Mapper_OnBeforeMapManyToOne; 

And then set NotNound to ignore the default ...

 private static void Mapper_OnBeforeMapManyToOne(IModelInspector modelInspector, PropertyPath propertyPath, IManyToOneMapper manyToOneMapper) { manyToOneMapper.NotFound(NotFoundMode.Ignore); } 
0
source

If you are using the .hbm.xml mapping file, then the "not found" option can be applied to it, for example

<many-to-one name="User" column="User" not-found="ignore" />

0
source

Source: https://habr.com/ru/post/1443402/


All Articles