title: How is Hibernate deciding order of update/insert/delete
body: <p>Let's first forget about Hibernate.  Assume that I have two tables, A &amp; B.  Two transactions are updating same records in these two tables, but txn 1 update B and then A, while txn 2 update A then B.  This is a typical deadlock example.  The most common way to avoid this is by pre-defining the order of acquiring resources.  For example, we should update table A then B.</p>
  
  <p>Go back to Hibernate.  When we are updating lots of entities in one session, once I am flushing the session, changes of different entities is going to generate corresponding insert/update/delete statements to DB.  Does Hibernate have some algorithm to decide the order of update among entities? If not, what is the way Hibernate used to prevent deadlock situation described in 1st paragraph?</p>
  
  <p>If Hibernate is maintaining the order, how can I know or control the order? I don't want my explicit update in DB conflicts with Hibernate, and cause deadlock.</p>