Skip to content

Commit c6f6ecc

Browse files
committed
make LAE extend PLE and clean up SQLStateConversionDelegate
- PessimisticLockException dupes the role of LockAcquisitionException - We should not have database-specific codes on SQLStateConversionDelegate - throw LAE instead of PLE on MySQL and Maria
1 parent 78bc800 commit c6f6ecc

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

hibernate-core/src/main/java/org/hibernate/PessimisticLockException.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
/**
1010
* Thrown when a pessimistic locking conflict occurs.
1111
*
12+
* @apiNote When a conflict is detected while acquiring a database-level lock,
13+
* {@link org.hibernate.exception.LockAcquisitionException} is preferred.
14+
*
1215
* @author Scott Marlow
1316
*
1417
* @see jakarta.persistence.PessimisticLockException
18+
* @see org.hibernate.exception.LockAcquisitionException
1519
*/
1620
public class PessimisticLockException extends JDBCException {
1721
/**
@@ -24,4 +28,14 @@ public class PessimisticLockException extends JDBCException {
2428
public PessimisticLockException(String message, SQLException sqlException, String sql) {
2529
super( message, sqlException, sql );
2630
}
31+
/**
32+
* Constructs a {@code PessimisticLockException} using the specified information.
33+
*
34+
* @param message A message explaining the exception condition
35+
* @param sqlException The underlying SQL exception
36+
*/
37+
public PessimisticLockException(String message, SQLException sqlException) {
38+
super( message, sqlException );
39+
40+
}
2741
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.sql.Types;
1010
import java.util.Set;
1111

12-
import org.hibernate.PessimisticLockException;
1312
import org.hibernate.QueryTimeoutException;
1413
import org.hibernate.boot.model.FunctionContributions;
1514
import org.hibernate.boot.model.TypeContributions;
@@ -355,12 +354,11 @@ public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
355354
switch ( sqlException.getErrorCode() ) {
356355
case 1205: // ER_LOCK_WAIT_TIMEOUT
357356
return new LockTimeoutException( message, sqlException, sql );
358-
case 3572: // ER_LOCK_NOWAIT
359-
return new PessimisticLockException( message, sqlException, sql );
360357
case 1020:
361358
// If @@innodb_snapshot_isolation is set (default since 11.6.2),
362359
// and an attempt to acquire a lock on a record that does not exist
363360
// in the current read view is made, error DB_RECORD_CHANGED is raised.
361+
case 3572: // ER_LOCK_NOWAIT
364362
case 1207: // ER_READ_ONLY_TRANSACTION
365363
case 1206: // ER_LOCK_TABLE_FULL
366364
return new LockAcquisitionException( message, sqlException, sql );

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import org.hibernate.Length;
1919
import org.hibernate.LockOptions;
20-
import org.hibernate.PessimisticLockException;
2120
import org.hibernate.QueryTimeoutException;
2221
import org.hibernate.boot.model.FunctionContributions;
2322
import org.hibernate.boot.model.TypeContributions;
@@ -1247,11 +1246,11 @@ public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
12471246
case 1205: // ER_LOCK_WAIT_TIMEOUT
12481247
return new LockTimeoutException( message, sqlException, sql );
12491248
case 3572: // ER_LOCK_NOWAIT
1250-
return new PessimisticLockException( message, sqlException, sql );
12511249
case 1207: // ER_READ_ONLY_TRANSACTION
12521250
case 1206: // ER_LOCK_TABLE_FULL
12531251
return new LockAcquisitionException( message, sqlException, sql );
12541252
case 3024: // ER_QUERY_TIMEOUT
1253+
case 1317: // ER_QUERY_INTERRUPTED
12551254
return new QueryTimeoutException( message, sqlException, sql );
12561255
case 1062:
12571256
// Unique constraint violation

hibernate-core/src/main/java/org/hibernate/exception/LockAcquisitionException.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.sql.SQLException;
88

9+
import org.hibernate.PessimisticLockException;
910
import org.hibernate.JDBCException;
1011

1112
/**
@@ -14,7 +15,7 @@
1415
*
1516
* @author Steve Ebersole
1617
*/
17-
public class LockAcquisitionException extends JDBCException {
18+
public class LockAcquisitionException extends PessimisticLockException {
1819
public LockAcquisitionException(String string, SQLException root) {
1920
super( string, root );
2021
}

hibernate-core/src/main/java/org/hibernate/exception/internal/SQLStateConversionDelegate.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import java.sql.SQLException;
88

99
import org.hibernate.JDBCException;
10-
import org.hibernate.PessimisticLockException;
11-
import org.hibernate.QueryTimeoutException;
1210
import org.hibernate.exception.AuthException;
1311
import org.hibernate.exception.ConstraintViolationException;
1412
import org.hibernate.exception.ConstraintViolationException.ConstraintKind;
@@ -22,7 +20,6 @@
2220
import org.checkerframework.checker.nullness.qual.Nullable;
2321

2422
import static org.hibernate.internal.util.JdbcExceptionHelper.determineSqlStateClassCode;
25-
import static org.hibernate.internal.util.JdbcExceptionHelper.extractErrorCode;
2623
import static org.hibernate.internal.util.JdbcExceptionHelper.extractSqlState;
2724

2825
/**
@@ -53,17 +50,6 @@ public SQLStateConversionDelegate(ConversionContext conversionContext) {
5350
return new AuthException( message, sqlException, sql );
5451
case "40001":
5552
return new LockAcquisitionException( message, sqlException, sql );
56-
case "40XL1", "40XL2":
57-
// Derby "A lock could not be obtained within the time requested."
58-
return new PessimisticLockException( message, sqlException, sql );
59-
case "70100":
60-
// MySQL Query execution was interrupted
61-
return new QueryTimeoutException( message, sqlException, sql );
62-
case "72000":
63-
if ( extractErrorCode( sqlException ) == 1013 ) {
64-
// Oracle user requested cancel of current operation
65-
return new QueryTimeoutException( message, sqlException, sql );
66-
}
6753
}
6854
switch ( determineSqlStateClassCode( sqlState ) ) {
6955
case

0 commit comments

Comments
 (0)