Skip to content

Commit

Permalink
Ensure we apply the exception converter consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Mar 10, 2023
1 parent 667a0ca commit bfcdc64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -183,6 +184,9 @@ public CompletionStage<R> getReactiveSingleResultOrNull() {
}

private R convertException(Throwable t) {
if ( t instanceof CompletionException ) {
t = t.getCause();
}
if ( t instanceof HibernateException ) {
throw getSession().getExceptionConverter().convert( (HibernateException) t, getLockOptions() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Collection;
import java.util.List;

import org.hibernate.NonUniqueResultException;

import org.junit.Test;

Expand Down Expand Up @@ -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()
) )
);
Expand All @@ -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()
) )
);
Expand Down

0 comments on commit bfcdc64

Please sign in to comment.