Skip to content

Commit 4b1adcd

Browse files
committed
throw QueryTimeoutException and LockTimeoutException on MySQL and Maria
1 parent 2e5a7f8 commit 4b1adcd

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

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

Lines changed: 8 additions & 5 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 );
360356
case 1205:
357+
return new LockTimeoutException( message, sqlException, sql );
361358
case 3572:
362359
return new PessimisticLockException( message, sqlException, sql );
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.
363364
case 1207:
364365
case 1206:
365366
return new LockAcquisitionException( message, sqlException, sql );
367+
case 3024:
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: 4 additions & 0 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;
@@ -1244,11 +1245,14 @@ public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
12441245
return (sqlException, message, sql) -> {
12451246
switch ( sqlException.getErrorCode() ) {
12461247
case 1205:
1248+
return new LockTimeoutException( message, sqlException, sql );
12471249
case 3572:
12481250
return new PessimisticLockException( message, sqlException, sql );
12491251
case 1207:
12501252
case 1206:
12511253
return new LockAcquisitionException( message, sqlException, sql );
1254+
case 3024:
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)