HHH-16399 Recognize ConstraintViolationException form errorCode in MSSQL

This is for Hibernate Reactive.

Hibernate ORM recognizes the error because, when it comes from the JDBC driver,
 it's an instance of `java.sql.SQLIntegrityConstraintViolationException`.
This commit is contained in:
Davide D'Alto 2023-03-30 10:33:25 +02:00 committed by Davide D'Alto
parent 75ca552e4e
commit d3629eb6fa
1 changed files with 4 additions and 0 deletions

View File

@ -46,6 +46,7 @@ import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.exception.LockTimeoutException;
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
import org.hibernate.internal.util.JdbcExceptionHelper;
@ -720,6 +721,9 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
if ( 1222 == errorCode ) {
throw new LockTimeoutException( message, sqlException, sql );
}
if ( 2627 == errorCode || 2601 == errorCode ) {
throw new ConstraintViolationException( message, sqlException, sql );
}
return null;
};
}