diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/spi/ReactiveAbstractSelectionQuery.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/spi/ReactiveAbstractSelectionQuery.java index 1e00002c0..1b090890e 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/spi/ReactiveAbstractSelectionQuery.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/spi/ReactiveAbstractSelectionQuery.java @@ -8,6 +8,7 @@ import java.lang.invoke.MethodHandles; import java.util.List; import java.util.Optional; +import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionStage; import java.util.function.Consumer; import java.util.function.Function; @@ -183,6 +184,9 @@ public CompletionStage getReactiveSingleResultOrNull() { } private R convertException(Throwable t) { + if ( t instanceof CompletionException ) { + t = t.getCause(); + } if ( t instanceof HibernateException ) { throw getSession().getExceptionConverter().convert( (HibernateException) t, getLockOptions() ); } diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/QueryTest.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/QueryTest.java index ac5424a8b..4d20eac28 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/QueryTest.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/QueryTest.java @@ -11,7 +11,6 @@ import java.util.Collection; import java.util.List; -import org.hibernate.NonUniqueResultException; import org.junit.Test; @@ -583,7 +582,7 @@ public void testSingleResultNonUniqueException(TestContext context) { .thenCompose( s -> s.persist( author1, author2 ).thenCompose( v -> s.flush() ) ) .thenCompose( v -> openSession() ) .thenCompose( s -> assertThrown( - org.hibernate.NonUniqueResultException.class, + jakarta.persistence.NonUniqueResultException.class, s.createQuery( "from Author" ).getSingleResult() ) ) ); @@ -597,7 +596,7 @@ public void testSingleResultOrNullNonUniqueException(TestContext context) { .thenCompose( s -> s.persist( author1, author2 ).thenCompose( v -> s.flush() ) ) .thenCompose( v -> openSession() ) .thenCompose( s -> assertThrown( - NonUniqueResultException.class, + jakarta.persistence.NonUniqueResultException.class, s.createQuery( "from Author" ).getSingleResultOrNull() ) ) );