Skip to content

Commit 265d47b

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 265d47b

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,11 @@ public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
355355
switch ( sqlException.getErrorCode() ) {
356356
case 1205: // ER_LOCK_WAIT_TIMEOUT
357357
return new LockTimeoutException( message, sqlException, sql );
358-
case 3572: // ER_LOCK_NOWAIT
359-
return new PessimisticLockException( message, sqlException, sql );
360358
case 1020:
361359
// If @@innodb_snapshot_isolation is set (default since 11.6.2),
362360
// and an attempt to acquire a lock on a record that does not exist
363361
// in the current read view is made, error DB_RECORD_CHANGED is raised.
362+
case 3572: // ER_LOCK_NOWAIT
364363
case 1207: // ER_READ_ONLY_TRANSACTION
365364
case 1206: // ER_LOCK_TABLE_FULL
366365
return new LockAcquisitionException( message, sqlException, sql );

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,11 +1247,11 @@ public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
12471247
case 1205: // ER_LOCK_WAIT_TIMEOUT
12481248
return new LockTimeoutException( message, sqlException, sql );
12491249
case 3572: // ER_LOCK_NOWAIT
1250-
return new PessimisticLockException( message, sqlException, sql );
12511250
case 1207: // ER_READ_ONLY_TRANSACTION
12521251
case 1206: // ER_LOCK_TABLE_FULL
12531252
return new LockAcquisitionException( message, sqlException, sql );
12541253
case 3024: // ER_QUERY_TIMEOUT
1254+
case 1317: // ER_QUERY_INTERRUPTED
12551255
return new QueryTimeoutException( message, sqlException, sql );
12561256
case 1062:
12571257
// 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)