Skip to content

Commit d63f77c

Browse files
committed
[hibernate#1514] Test lazy exception with transaction
1 parent c7afdaf commit d63f77c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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

+27
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.junit.jupiter.api.BeforeEach;
1818
import org.junit.jupiter.api.Test;
1919

20+
import io.smallrye.mutiny.Uni;
2021
import io.vertx.junit5.Timeout;
2122
import io.vertx.junit5.VertxTestContext;
2223
import jakarta.persistence.Entity;
@@ -32,6 +33,7 @@
3233
import static java.util.concurrent.TimeUnit.MINUTES;
3334
import static org.assertj.core.api.Assertions.assertThat;
3435
import static org.hibernate.reactive.testing.ReactiveAssertions.assertThrown;
36+
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
3537
import static org.junit.jupiter.api.Assertions.assertEquals;
3638
import static org.junit.jupiter.api.Assertions.assertTrue;
3739

@@ -61,6 +63,31 @@ public void populateDB(VertxTestContext context) {
6163
test( context, getSessionFactory().withTransaction( session -> session.persist( artemisia, liuto, sev ) ) );
6264
}
6365

66+
@Test
67+
public void testLazyInitializationExceptionWithTransactionWithMutiny(VertxTestContext context) {
68+
test( context, assertThrown( LazyInitializationException.class, getMutinySessionFactory()
69+
.withSession( ms -> ms
70+
.createSelectionQuery( "from Artist", Artist.class )
71+
.getSingleResult() )
72+
.call( artist -> getMutinySessionFactory().withTransaction( s -> Uni.createFrom()
73+
// .size should throw LazyInitializationException
74+
.item( artist.getPaintings().size() ) ) )
75+
)
76+
);
77+
}
78+
79+
@Test
80+
public void testLazyInitializationExceptionWithTransactionWithStage(VertxTestContext context) {
81+
test( context, assertThrown( LazyInitializationException.class, getSessionFactory()
82+
.withSession( ss -> ss
83+
.createSelectionQuery( "from Artist", Artist.class )
84+
.getSingleResult() )
85+
.thenCompose( artist -> getSessionFactory()
86+
.withTransaction( s -> completedFuture( artist.getPaintings().size() ) ) )
87+
)
88+
);
89+
}
90+
6491
@Test
6592
public void testLazyInitializationExceptionWithMutiny(VertxTestContext context) {
6693
test( context, assertThrown( LazyInitializationException.class, openMutinySession()

0 commit comments

Comments
 (0)