Skip to content

Commit 946e6b8

Browse files
committed
properly handle the nested nature of the Informix ISAM error
it comes wrapped in a containing exception with diff error code
1 parent f5c00dc commit 946e6b8

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -584,26 +584,35 @@ public boolean supportsValuesListForInsert() {
584584

585585
@Override
586586
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
587-
return (sqlException, message, sql) ->
588-
switch ( extractErrorCode( sqlException ) ) {
589-
case -378, -233, -107, -113, -134, -143, -144, -154 ->
590-
//TODO: which of these are these are really LockTimeoutExceptions
591-
// rather than the more generic LockAcquisitionException?
592-
new LockAcquisitionException( message, sqlException, sql );
593-
case -239, -268 ->
594-
new ConstraintViolationException( message, sqlException, sql, ConstraintViolationException.ConstraintKind.UNIQUE,
595-
getViolatedConstraintNameExtractor().extractConstraintName( sqlException ) );
596-
case -691, -692 ->
597-
new ConstraintViolationException( message, sqlException, sql, ConstraintViolationException.ConstraintKind.FOREIGN_KEY,
598-
getViolatedConstraintNameExtractor().extractConstraintName( sqlException ) );
599-
case -703, -391 ->
600-
new ConstraintViolationException( message, sqlException, sql, ConstraintViolationException.ConstraintKind.NOT_NULL,
601-
getViolatedConstraintNameExtractor().extractConstraintName( sqlException ) );
602-
case -530 ->
603-
new ConstraintViolationException( message, sqlException, sql, ConstraintViolationException.ConstraintKind.CHECK,
604-
getViolatedConstraintNameExtractor().extractConstraintName( sqlException ) );
605-
default -> null;
606-
};
587+
return (exception, message, sql) -> switch ( extractErrorCode( exception ) ) {
588+
case -239, -268 ->
589+
new ConstraintViolationException( message, exception, sql, ConstraintViolationException.ConstraintKind.UNIQUE,
590+
getViolatedConstraintNameExtractor().extractConstraintName( exception ) );
591+
case -691, -692 ->
592+
new ConstraintViolationException( message, exception, sql, ConstraintViolationException.ConstraintKind.FOREIGN_KEY,
593+
getViolatedConstraintNameExtractor().extractConstraintName( exception ) );
594+
case -703, -391 ->
595+
new ConstraintViolationException( message, exception, sql, ConstraintViolationException.ConstraintKind.NOT_NULL,
596+
getViolatedConstraintNameExtractor().extractConstraintName( exception ) );
597+
case -530 ->
598+
new ConstraintViolationException( message, exception, sql, ConstraintViolationException.ConstraintKind.CHECK,
599+
getViolatedConstraintNameExtractor().extractConstraintName( exception ) );
600+
default -> {
601+
// unwrap the ISAM error, if any
602+
if ( exception.getCause() instanceof SQLException cause && cause != exception ) {
603+
yield switch ( extractErrorCode( cause ) ) {
604+
case -107, -113, -134, -143, -144, -154 ->
605+
//TODO: which of these are these are really LockTimeoutExceptions
606+
// rather than the more generic LockAcquisitionException?
607+
new LockAcquisitionException( message, exception, sql );
608+
default -> null;
609+
};
610+
}
611+
else {
612+
yield null;
613+
}
614+
}
615+
};
607616
}
608617

609618
@Override

hibernate-core/src/test/java/org/hibernate/orm/test/collection/multisession/MultipleSessionCollectionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import jakarta.persistence.GeneratedValue;
1313
import jakarta.persistence.Id;
1414
import jakarta.persistence.JoinColumn;
15-
import jakarta.persistence.LockTimeoutException;
1615
import jakarta.persistence.OneToMany;
1716
import jakarta.persistence.OptimisticLockException;
17+
import jakarta.persistence.PessimisticLockException;
1818

1919
import org.hibernate.Hibernate;
2020
import org.hibernate.collection.spi.AbstractPersistentCollection;
@@ -23,9 +23,9 @@
2323
import org.hibernate.dialect.HSQLDialect;
2424
import org.hibernate.engine.spi.CollectionEntry;
2525

26+
import org.hibernate.exception.LockTimeoutException;
2627
import org.hibernate.testing.orm.junit.JiraKey;
2728
import org.hibernate.testing.orm.junit.DomainModel;
28-
import org.hibernate.testing.orm.junit.JiraKey;
2929
import org.hibernate.testing.orm.junit.SessionFactory;
3030
import org.hibernate.testing.orm.junit.SessionFactoryScope;
3131
import org.hibernate.testing.orm.junit.SkipForDialect;
@@ -120,7 +120,7 @@ public void testCopyPersistentCollectionReferenceAfterFlush(SessionFactoryScope
120120
s2.getTransaction().commit();
121121
fail( "should have thrown HibernateException" );
122122
}
123-
catch (OptimisticLockException | LockTimeoutException ex) {
123+
catch (OptimisticLockException | PessimisticLockException | LockTimeoutException ex) {
124124
// expected
125125
s2.getTransaction().rollback();
126126
}

0 commit comments

Comments
 (0)