Skip to content

Document that DataIntegrityViolationException can also be thrown on read-only queries #32631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kirk-b-hansen opened this issue Apr 12, 2024 · 1 comment
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: backported An issue that has been backported to maintenance branches type: documentation A documentation task
Milestone

Comments

@kirk-b-hansen
Copy link

Affects: at least v4.0.0+


The javadoc for DataIntegrityViolationException specifies "Exception thrown when an attempt to insert or update data results in violation of an integrity constraint.". However, HibernateJpaDialect#convertHibernateAccessException will convert any org.hibernate.exception.DataException to a DataIntegrityViolationException. org.hibernate.exception.DataException indicates "that evaluation of the valid SQL statement against the given data resulted in some illegal operation, mismatched types or incorrect cardinality", which isn't necessarily limited to inserts or updates. For example, org.postgresql.util.PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0x00 on a select query with a null character in a query param can end up throwing org.hibernate.exception.DataException.

It's slightly confusing that the documention for DataIntegrityViolationException specifies that it's only thrown on an insert or update, but it can also be thrown on read-only queries.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 12, 2024
@snicoll
Copy link
Member

snicoll commented Apr 13, 2024

Thanks for the report. My best guess is that the scope of DataException extended and we didn't notice it. We'll have a look.

@snicoll snicoll added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Apr 13, 2024
@snicoll snicoll added type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 22, 2024
@snicoll snicoll added this to the 6.1.7 milestone Apr 22, 2024
@snicoll snicoll self-assigned this Apr 22, 2024
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-6.0.x labels Apr 22, 2024
@snicoll snicoll changed the title DataIntegrityViolationException can be thrown on read-only queries Document that DataIntegrityViolationException can also be thrown on read-only queries Apr 22, 2024
@snicoll snicoll changed the title Document that DataIntegrityViolationException can also be thrown on read-only queries Document that DataIntegrityViolationException can also be thrown on read-only queries Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: backported An issue that has been backported to maintenance branches type: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

3 participants