Skip to content

Commit bfcdc64

Browse files
committed
Ensure we apply the exception converter consistently
1 parent 667a0ca commit bfcdc64

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/spi/ReactiveAbstractSelectionQuery.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.lang.invoke.MethodHandles;
99
import java.util.List;
1010
import java.util.Optional;
11+
import java.util.concurrent.CompletionException;
1112
import java.util.concurrent.CompletionStage;
1213
import java.util.function.Consumer;
1314
import java.util.function.Function;
@@ -183,6 +184,9 @@ public CompletionStage<R> getReactiveSingleResultOrNull() {
183184
}
184185

185186
private R convertException(Throwable t) {
187+
if ( t instanceof CompletionException ) {
188+
t = t.getCause();
189+
}
186190
if ( t instanceof HibernateException ) {
187191
throw getSession().getExceptionConverter().convert( (HibernateException) t, getLockOptions() );
188192
}

hibernate-reactive-core/src/test/java/org/hibernate/reactive/QueryTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.util.Collection;
1212
import java.util.List;
1313

14-
import org.hibernate.NonUniqueResultException;
1514

1615
import org.junit.Test;
1716

@@ -583,7 +582,7 @@ public void testSingleResultNonUniqueException(TestContext context) {
583582
.thenCompose( s -> s.persist( author1, author2 ).thenCompose( v -> s.flush() ) )
584583
.thenCompose( v -> openSession() )
585584
.thenCompose( s -> assertThrown(
586-
org.hibernate.NonUniqueResultException.class,
585+
jakarta.persistence.NonUniqueResultException.class,
587586
s.createQuery( "from Author" ).getSingleResult()
588587
) )
589588
);
@@ -597,7 +596,7 @@ public void testSingleResultOrNullNonUniqueException(TestContext context) {
597596
.thenCompose( s -> s.persist( author1, author2 ).thenCompose( v -> s.flush() ) )
598597
.thenCompose( v -> openSession() )
599598
.thenCompose( s -> assertThrown(
600-
NonUniqueResultException.class,
599+
jakarta.persistence.NonUniqueResultException.class,
601600
s.createQuery( "from Author" ).getSingleResultOrNull()
602601
) )
603602
);

0 commit comments

Comments
 (0)