1

Preface: This question is a derivative of this answer, speaking specifically about NHibernate instead of Hibernate.

As to Hibernate, javadoc to org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(EventSource) says:

Execute all SQL and second-level cache updates, in a special order so that foreign-key constraints cannot be violated:

  1. Inserts, in the order they were performed
  2. Updates Deletion of collection elements
  3. Insertion of collection elements
  4. Deletes, in the order they were performed

My Questions:

  1. If it applies to Hibernate, does this order apply to NHibernate too?
  2. Is this deterministic order documented somewhere?

Also - If this behavior is DBMS-specific, I'm using SQL Server.

Community
  • 1
  • 1
Jim G.
  • 15,141
  • 22
  • 103
  • 166

1 Answers1

4

The documentation of NHibernate 3.3 is in detail describing the steps when the Session.Flush is called (point 9.6). In case of session.FlushMode = FlushMode.Commit; this is how the transaction batch will be executed:

The steps are:

  • 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()

I am mostly using SQL Server (2008) and can say that this is working this way..

Cole W
  • 15,123
  • 6
  • 51
  • 85
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335