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