Skip to content

Conversation

beikov
Copy link
Member

@beikov beikov commented Aug 28, 2025

[Please describe here what your change is about]


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-19725
https://hibernate.atlassian.net/browse/HHH-18217

Comment on lines +159 to +168
if ( cve.getKind() == UNIQUE ) {
if ( valueBindings.isEmpty() ) {
// Ignore primary key violation if the insert is composed of just the primary key
return;
}
// assume it was the primary key constraint which was violated,
// due to a new version of the row existing in the database
throw new StaleStateException( mutationTarget.getRolePath(), cve );
}
throw cve;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ( cve.getKind() == UNIQUE ) {
if ( valueBindings.isEmpty() ) {
// Ignore primary key violation if the insert is composed of just the primary key
return;
}
// assume it was the primary key constraint which was violated,
// due to a new version of the row existing in the database
throw new StaleStateException( mutationTarget.getRolePath(), cve );
}
throw cve;
if ( cve.getKind() == UNIQUE ) {
// Ignore primary key violation if the insert is composed of just the primary key
if ( !valueBindings.isEmpty() ) {
// assume it was the primary key constraint which was violated,
// due to a new version of the row existing in the database
throw new StaleStateException( mutationTarget.getRolePath(), cve );
}
}
else {
throw cve;
}

@gavinking
Copy link
Member

gavinking commented Aug 30, 2025

Thanks for working on this one, Christian.

One doubt I have is: there are two different cases here:

  • management of secondary table updates (the original purpose of this code)
  • upserts of primary tables (my abuse of Steve's original code)

Looking at these changes I can't clearly see where the difference between the two usages is manifest. It might be enough to just add a comment or something, but I would definitely like maintainers to have some warning about this subtlety. WDYT?

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.

3 participants