Skip to content

Commit e640d47

Browse files
committed
[#2314] Test setMaxResults() on native queries
1 parent 5b84fb6 commit e640d47

File tree

1 file changed

+37
-0
lines changed
  • hibernate-reactive-core/src/test/java/org/hibernate/reactive

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static jakarta.persistence.FetchType.LAZY;
4444
import static java.util.concurrent.TimeUnit.MINUTES;
4545
import static org.assertj.core.api.Assertions.assertThat;
46+
import static org.assertj.core.groups.Tuple.tuple;
4647
import static org.hibernate.reactive.QueryTest.Author.AUTHOR_TABLE;
4748
import static org.hibernate.reactive.QueryTest.Author.HQL_NAMED_QUERY;
4849
import static org.hibernate.reactive.QueryTest.Author.SQL_NAMED_QUERY;
@@ -395,6 +396,42 @@ public void testNativeEntityQueryWithParam(VertxTestContext context) {
395396
);
396397
}
397398

399+
// https://github.com/hibernate/hibernate-reactive/issues/2314
400+
@Test
401+
public void testNativeEntityQueryWithLimit(VertxTestContext context) {
402+
Author author1 = new Author( "Iain M. Banks" );
403+
Author author2 = new Author( "Neal Stephenson" );
404+
Book book1 = new Book( "1-85723-235-6", "Feersum Endjinn", author1 );
405+
Book book2 = new Book( "0-380-97346-4", "Cryptonomicon", author2 );
406+
Book book3 = new Book( "0-553-08853-X", "Snow Crash", author2 );
407+
author1.books.add( book1 );
408+
author2.books.add( book2 );
409+
author2.books.add( book3 );
410+
411+
test(
412+
context,
413+
openSession()
414+
.thenCompose( session -> session.persist( author1, author2 )
415+
.thenCompose( v -> session.flush() )
416+
)
417+
.thenCompose( v -> openSession() )
418+
.thenCompose( session -> session.createNativeQuery(
419+
"select * from " + BOOK_TABLE + " order by isbn",
420+
Book.class
421+
)
422+
.setMaxResults( 2 )
423+
.getResultList() )
424+
.thenAccept( books -> {
425+
assertThat( books )
426+
.extracting( b -> b.id, b -> b.title, b -> b.isbn )
427+
.containsExactly(
428+
tuple( book2.id, book2.title, book2.isbn ),
429+
tuple( book3.id, book3.title, book3.isbn )
430+
);
431+
} )
432+
);
433+
}
434+
398435
@Test
399436
public void testNativeEntityQueryWithNamedParam(VertxTestContext context) {
400437
Author author1 = new Author( "Iain M. Banks" );

0 commit comments

Comments
 (0)