Order of operations
When you save an instance of a complex entity such as Employee
which may have associations to several other entities, NHibernate has to do a lot of work to figure out how to insert/update/delete particular database records. It is important to not only generate correct set of SQL statements to get the work done, but it is even more important to fire these SQL statements in right order. With complex database table structures with lot of foreign key associations, it may be daunting to figure out right order of running a set of SQL statements. NHibernate makes the job easy for us by using the following order to ensure that SQL statements always go in right order:
All entity insertions in the same order they were passed into the
Save
method of session.All entity updates.
All collection deletions.
All collection element deletions, updates, and insertions.
All collection insertions.
All entity deletions in the same order they were passed into the
Delete
method of session.
You do not...