Skip to content

Commit b31505f

Browse files
committed
throw QueryTimeoutException and LockTimeoutException on MySQL and Maria
1 parent a706c64 commit b31505f

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Set;
1111

1212
import org.hibernate.PessimisticLockException;
13+
import org.hibernate.QueryTimeoutException;
1314
import org.hibernate.boot.model.FunctionContributions;
1415
import org.hibernate.boot.model.TypeContributions;
1516
import org.hibernate.dialect.aggregate.AggregateSupport;
@@ -352,17 +353,19 @@ public ViolatedConstraintNameExtractor getViolatedConstraintNameExtractor() {
352353
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
353354
return (sqlException, message, sql) -> {
354355
switch ( sqlException.getErrorCode() ) {
355-
// If @@innodb_snapshot_isolation is set (default since 11.6.2),
356-
// if an attempt to acquire a lock on a record that does not exist in the current read view is made,
357-
// an error DB_RECORD_CHANGED will be raised.
358-
case 1020:
359-
return new LockAcquisitionException( message, sqlException, sql );
360-
case 1205:
361-
case 3572:
356+
case 1205: // ER_LOCK_WAIT_TIMEOUT
357+
return new LockTimeoutException( message, sqlException, sql );
358+
case 3572: // ER_LOCK_NOWAIT
362359
return new PessimisticLockException( message, sqlException, sql );
363-
case 1207:
364-
case 1206:
360+
case 1020:
361+
// If @@innodb_snapshot_isolation is set (default since 11.6.2),
362+
// and an attempt to acquire a lock on a record that does not exist
363+
// in the current read view is made, error DB_RECORD_CHANGED is raised.
364+
case 1207: // ER_READ_ONLY_TRANSACTION
365+
case 1206: // ER_LOCK_TABLE_FULL
365366
return new LockAcquisitionException( message, sqlException, sql );
367+
case 3024: // ER_QUERY_TIMEOUT
368+
return new QueryTimeoutException( message, sqlException, sql );
366369
case 1062:
367370
// Unique constraint violation
368371
return new ConstraintViolationException( message, sqlException, sql, ConstraintKind.UNIQUE,

hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.hibernate.Length;
1919
import org.hibernate.LockOptions;
2020
import org.hibernate.PessimisticLockException;
21+
import org.hibernate.QueryTimeoutException;
2122
import org.hibernate.boot.model.FunctionContributions;
2223
import org.hibernate.boot.model.TypeContributions;
2324
import org.hibernate.cfg.AvailableSettings;
@@ -1243,12 +1244,15 @@ public boolean supportsLockTimeouts() {
12431244
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
12441245
return (sqlException, message, sql) -> {
12451246
switch ( sqlException.getErrorCode() ) {
1246-
case 1205:
1247-
case 3572:
1247+
case 1205: // ER_LOCK_WAIT_TIMEOUT
1248+
return new LockTimeoutException( message, sqlException, sql );
1249+
case 3572: // ER_LOCK_NOWAIT
12481250
return new PessimisticLockException( message, sqlException, sql );
1249-
case 1207:
1250-
case 1206:
1251+
case 1207: // ER_READ_ONLY_TRANSACTION
1252+
case 1206: // ER_LOCK_TABLE_FULL
12511253
return new LockAcquisitionException( message, sqlException, sql );
1254+
case 3024: // ER_QUERY_TIMEOUT
1255+
return new QueryTimeoutException( message, sqlException, sql );
12521256
case 1062:
12531257
// Unique constraint violation
12541258
return new ConstraintViolationException( message, sqlException, sql, ConstraintKind.UNIQUE,

0 commit comments

Comments
 (0)