Why update statements in a transaction are always reorderd by hibernate

I am learning how to use hibernate (5.4.32.Final), and I found update in my transaction are always reordered by the primary key. After look up document, I know there is a property hibernate.order_updates, which can force hibernate to change the order of udpates. But its default value is false, and even I explictly set it as false, the order of update operations in transaction still changed (not same as the order of persist call).
I know this reorder can help reduce the probability of deadlock under high concurrency, but I still hope I can control the order of update statements without manually flush between them. What should I do?

The following is my code and log.
T1 is a table containing 2 columns id and value, and T2 is a table containing 3 columns id, t1_id and values. They have OneToMany relationship.
And the order of update operations is changed by hibernate.

        T1 t1 = getById(session, row_id, false);
        List<T2> t2s = t1.getT2();
        Collections.shuffle(t2s);
        Random random = new Random();

        transaction.begin();
        for(T2 t2 : t2s){
            t2.setValue(random.nextInt(100000));
            session.persist(t2);
//            session.flush();
        }
        t1.setValue(random.nextInt(100000));
        session.persist(t1);
        transaction.commit();
2021-06-30 20:03:41 [Thread-2] DEBUG org.hibernate.SQL - update T1 set value=? where id=?
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [63221]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [BIGINT] - [37]
2021-06-30 20:03:41 [Thread-2] DEBUG org.hibernate.SQL - update T2 set t1_id=?, value=? where id=?
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [37]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [BIGINT] - [74295]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [BIGINT] - [361]
2021-06-30 20:03:41 [Thread-2] DEBUG org.hibernate.SQL - update T2 set t1_id=?, value=? where id=?
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [37]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [BIGINT] - [16209]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [BIGINT] - [362]
2021-06-30 20:03:41 [Thread-2] DEBUG org.hibernate.SQL - update T2 set t1_id=?, value=? where id=?
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [37]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [BIGINT] - [31364]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [BIGINT] - [363]
2021-06-30 20:03:41 [Thread-2] DEBUG org.hibernate.SQL - update T2 set t1_id=?, value=? where id=?
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [37]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [BIGINT] - [17351]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [BIGINT] - [364]
2021-06-30 20:03:41 [Thread-2] DEBUG org.hibernate.SQL - update T2 set t1_id=?, value=? where id=?
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [37]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [BIGINT] - [50964]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [BIGINT] - [365]
2021-06-30 20:03:41 [Thread-2] DEBUG org.hibernate.SQL - update T2 set t1_id=?, value=? where id=?
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [37]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [BIGINT] - [25135]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [BIGINT] - [366]
2021-06-30 20:03:41 [Thread-2] DEBUG org.hibernate.SQL - update T2 set t1_id=?, value=? where id=?
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [37]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [BIGINT] - [79969]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [BIGINT] - [367]
2021-06-30 20:03:41 [Thread-2] DEBUG org.hibernate.SQL - update T2 set t1_id=?, value=? where id=?
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [37]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [BIGINT] - [53048]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [BIGINT] - [368]
2021-06-30 20:03:41 [Thread-2] DEBUG org.hibernate.SQL - update T2 set t1_id=?, value=? where id=?
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [37]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [BIGINT] - [23097]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [BIGINT] - [369]
2021-06-30 20:03:41 [Thread-2] DEBUG org.hibernate.SQL - update T2 set t1_id=?, value=? where id=?
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [37]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [BIGINT] - [71799]
2021-06-30 20:03:41 [Thread-2] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [BIGINT] - [370]

Why do you care about the actual order? Hibernate has internal data structures to manage entities which might not retain the order as you attach entities. Sometimes, cascading can also play a role, but overall, Hibernate will at least reorder entities according to foreign key dependencies.

Thanks for your reply!
But in my case, firstly, the update for table T1 and T2 is reordered. Secondly, for table T2, its update is also reordered by primary key, why hibernate did so even though order_updates is false? I just want to learn how and why hibernate work so, there should be some reasons.
And there may be a document including the description about how hibernate maintain the order of entities and the order of persistence, so that you can avoid explaining too much for me.

T2 is dependent on T1, so T1 is persisted/updated before, otherwise you might get a constraint violation error. The reordering of T2 is probably due to the internal algorithm needing a stable ordering. You can look into the ActionQueue class if you want to understand all the details.

I have realized the reason why the order of update statements doesn’t follow my persist call.
My session.persist() call is redundant, and all entities have been in session.persistenceContext after they were retrived from database.
So in my case hibernate issue update statements according the order of entity join into the session.persistenceContext, which is the order I read them rather than I try to “persist” them.