From cb3f2bce4722aa0cd9524f8fb60a37452e3bfa2a Mon Sep 17 00:00:00 2001 From: gbrodman Date: Thu, 17 Sep 2026 19:25:07 +0000 Subject: [PATCH] Add insert+update sort for Hibernate (#3235) When inserting multiple entities, if sorting isn't enabled, then Hibernate will just add them in the order received. This is suboptimal for batch query execution. Hibernate flushes the batch as soon as it "encounters" a new table, so if we have inserts into tables A, B, A, B in that order, it'll execute each one separately, rather than batching (A,A), (B,B). The downside to enabling ordering is that you need to either have deferred foreign keys (which we have) or Hibernate-style entity references, e.g. `@OneToOne Entity entity` rather than `VKey entityId`. While any future potential migration to Spanner would require that we remove the deferred foreign keys, this change is orthogonal to that -- we'll need to change the references to direct Hibernate references anyway which Hibernate will know how to order properly. --- .../java/google/registry/persistence/PersistenceModule.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/main/java/google/registry/persistence/PersistenceModule.java b/core/src/main/java/google/registry/persistence/PersistenceModule.java index bad958313..257034797 100644 --- a/core/src/main/java/google/registry/persistence/PersistenceModule.java +++ b/core/src/main/java/google/registry/persistence/PersistenceModule.java @@ -116,6 +116,8 @@ public abstract class PersistenceModule { properties.put(JDBC_BATCH_SIZE, Integer.toString(getHibernateJdbcBatchSize())); properties.put(JDBC_FETCH_SIZE, getHibernateJdbcFetchSize()); properties.put(DEFAULT_BATCH_FETCH_SIZE, Integer.toString(getHibernateDefaultBatchFetchSize())); + properties.put(Environment.ORDER_INSERTS, "true"); + properties.put(Environment.ORDER_UPDATES, "true"); return properties.build(); }