Add insert+update sort for Hibernate - #3235
Merged
Merged
Conversation
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.
weiminyu
approved these changes
Sep 17, 2026
weiminyu
left a comment
Collaborator
There was a problem hiding this comment.
@weiminyu reviewed 1 file and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on gbrodman).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 entityrather thanVKey<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