How is Hibernate deciding order of update/insert/delete

前端 未结 2 989
半阙折子戏
半阙折子戏 2020-12-05 02:30

Let\'s first forget about Hibernate. Assume that I have two tables, A & B. Two transactions are updating same records in these two tables, but txn 1 update B and then

2条回答
  •  隐瞒了意图╮
    2020-12-05 02:57

    Regarding first example - this kind of stuff is handled by database (read more about transaction isolation levels and locking strategies of your database). There are many different ways this can be handled.

    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

    I assume that this is the only optimization of executed SQL queries Hibernate makes. The rest of problems is handled by database.

提交回复
热议问题