fix for Dialects with null SQLException delegate
This commit is contained in:
parent
6b5c11b1ff
commit
5dbf9aedf9
|
@ -28,6 +28,7 @@ import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
|
|||
import org.hibernate.exception.internal.SQLExceptionTypeDelegate;
|
||||
import org.hibernate.exception.internal.SQLStateConversionDelegate;
|
||||
import org.hibernate.exception.internal.StandardSQLExceptionConverter;
|
||||
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||
|
@ -335,13 +336,11 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
|||
}
|
||||
|
||||
private SqlExceptionHelper buildSqlExceptionHelper(Dialect dialect, boolean logWarnings) {
|
||||
final StandardSQLExceptionConverter sqlExceptionConverter = new StandardSQLExceptionConverter(
|
||||
dialect.buildSQLExceptionConversionDelegate(),
|
||||
new SQLExceptionTypeDelegate( dialect ),
|
||||
// todo : vary this based on extractedMetaDataSupport.getSqlStateType()
|
||||
new SQLStateConversionDelegate( dialect )
|
||||
);
|
||||
return new SqlExceptionHelper( sqlExceptionConverter, logWarnings );
|
||||
SQLExceptionConversionDelegate dialectDelegate = dialect.buildSQLExceptionConversionDelegate();
|
||||
SQLExceptionConversionDelegate[] delegates = dialectDelegate == null
|
||||
? new SQLExceptionConversionDelegate[] { new SQLExceptionTypeDelegate( dialect ), new SQLStateConversionDelegate( dialect ) }
|
||||
: new SQLExceptionConversionDelegate[] { dialectDelegate, new SQLExceptionTypeDelegate( dialect ), new SQLStateConversionDelegate( dialect ) };
|
||||
return new SqlExceptionHelper( new StandardSQLExceptionConverter(delegates), logWarnings );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,9 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.exception;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
@ -20,7 +18,6 @@ import org.hibernate.engine.jdbc.spi.StatementPreparer;
|
|||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.hibernate.jdbc.Work;
|
||||
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
@ -51,14 +48,12 @@ public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
|
|||
value = { AbstractHANADialect.class, TiDBDialect.class},
|
||||
comment = "MySQL (MyISAM) / Hana / TiDB do not support FK violation checking"
|
||||
)
|
||||
public void testIntegrityViolation() throws Exception {
|
||||
public void testIntegrityViolation() {
|
||||
final Session session = openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
session.doWork(
|
||||
new Work() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
connection -> {
|
||||
// Attempt to insert some bad values into the T_MEMBERSHIP table that should
|
||||
// result in a constraint violation
|
||||
PreparedStatement ps = null;
|
||||
|
@ -77,7 +72,6 @@ public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
|
|||
releaseStatement( session, ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
session.getTransaction().rollback();
|
||||
|
@ -85,14 +79,12 @@ public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBadGrammar() throws Exception {
|
||||
public void testBadGrammar() {
|
||||
final Session session = openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
session.doWork(
|
||||
new Work() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
connection -> {
|
||||
// prepare/execute a query against a non-existent table
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
|
@ -108,7 +100,6 @@ public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
|
|||
releaseStatement( session, ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
session.getTransaction().rollback();
|
||||
|
@ -127,9 +118,7 @@ public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
|
|||
session.flush();
|
||||
|
||||
session.doWork(
|
||||
new Work() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
connection -> {
|
||||
final JdbcCoordinator jdbcCoordinator = ( (SessionImplementor) session ).getJdbcCoordinator();
|
||||
final StatementPreparer statementPreparer = jdbcCoordinator.getStatementPreparer();
|
||||
final ResultSetReturn resultSetReturn = jdbcCoordinator.getResultSetReturn();
|
||||
|
@ -149,7 +138,6 @@ public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
|
|||
releaseStatement( session, ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
session.getTransaction().rollback();
|
||||
|
|
Loading…
Reference in New Issue