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.

Comment From: snicoll

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.