Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nhibernate order of SQL statements when flushing session

According to NHibernate documentation, SQL statements are issued in the following order when a session is flushed:

  • all entity insertions, in the same order the corresponding objects were saved using ISession.Save()
  • all entity updates
  • all collection deletions
  • all collection element deletions, updates and insertions
  • all collection insertions
  • all entity deletions, in the same order the corresponding objects were deleted using ISession.Delete()

Why is it forced in this order and is there any way to change it so that the statements are executed in the same order that I give them?

like image 490
LMC Avatar asked Dec 14 '10 19:12

LMC


1 Answers

It's in that order because it's the safest.

And no, you can't change the order. But also, you never gave NHibernate any order: you just mark entities for persistence; NHibernate determines what to do automatically.

If you think you need more control over individual SQL operations, you can use IStatelessSession instead of a regular ISession. You lose all the stuff NH does automatically (lazy loading, caching, dirty-tracking), but you can (must) say explicitly when to Insert, Delete or Update a record.

like image 193
Diego Mijelshon Avatar answered Sep 27 '22 15:09

Diego Mijelshon