Skip to content

Add insert+update sort for Hibernate - #3235

Merged
gbrodman merged 1 commit into
google:masterfrom
gbrodman:hibernateOrder
Sep 17, 2026
Merged

gbrodman merged 1 commit into
google:masterfrom
gbrodman:hibernateOrder

Conversation

@gbrodman

@gbrodman gbrodman commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

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<String> 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.


This change is Reviewable

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<String>
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.
@gbrodman
gbrodman requested a review from weiminyu September 17, 2026 19:04

@weiminyu weiminyu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weiminyu reviewed 1 file and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on gbrodman).

@gbrodman
gbrodman enabled auto-merge September 17, 2026 19:07
@gbrodman
gbrodman added this pull request to the merge queue Sep 17, 2026
Merged via the queue into google:master with commit cb3f2bc Sep 17, 2026
16 checks passed
@gbrodman
gbrodman deleted the hibernateOrder branch September 17, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants