Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ private CompletionStage<ResultSet> executeQuery() {
return completedFuture( logicalConnection )
.thenCompose( lg -> {
LOG.tracef( "Executing query to retrieve ResultSet : %s", getFinalSql() );

Dialect dialect = DialectDelegateWrapper.extractRealDialect( executionContext.getSession().getJdbcServices().getDialect() );
// I'm not sure calling Parameters here is necessary, the query should already have the right parameters

// This must happen at the very last minute in order to process parameters
// added in org.hibernate.dialect.pagination.OffsetFetchLimitHandler.processSql
final String sql = Parameters.instance( dialect ).process( getFinalSql() );
Object[] parameters = PreparedStatementAdaptor.bind( super::bindParameters );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static jakarta.persistence.FetchType.LAZY;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.groups.Tuple.tuple;
import static org.hibernate.reactive.QueryTest.Author.AUTHOR_TABLE;
import static org.hibernate.reactive.QueryTest.Author.HQL_NAMED_QUERY;
import static org.hibernate.reactive.QueryTest.Author.SQL_NAMED_QUERY;
Expand Down Expand Up @@ -395,6 +396,42 @@ public void testNativeEntityQueryWithParam(VertxTestContext context) {
);
}

// https://github.com/hibernate/hibernate-reactive/issues/2314
@Test
public void testNativeEntityQueryWithLimit(VertxTestContext context) {
Author author1 = new Author( "Iain M. Banks" );
Author author2 = new Author( "Neal Stephenson" );
Book book1 = new Book( "1-85723-235-6", "Feersum Endjinn", author1 );
Book book2 = new Book( "0-380-97346-4", "Cryptonomicon", author2 );
Book book3 = new Book( "0-553-08853-X", "Snow Crash", author2 );
author1.books.add( book1 );
author2.books.add( book2 );
author2.books.add( book3 );

test(
context,
openSession()
.thenCompose( session -> session.persist( author1, author2 )
.thenCompose( v -> session.flush() )
)
.thenCompose( v -> openSession() )
.thenCompose( session -> session.createNativeQuery(
"select * from " + BOOK_TABLE + " order by isbn",
Book.class
)
.setMaxResults( 2 )
.getResultList() )
.thenAccept( books -> {
assertThat( books )
.extracting( b -> b.id, b -> b.title, b -> b.isbn )
.containsExactly(
tuple( book2.id, book2.title, book2.isbn ),
tuple( book3.id, book3.title, book3.isbn )
);
} )
);
}

@Test
public void testNativeEntityQueryWithNamedParam(VertxTestContext context) {
Author author1 = new Author( "Iain M. Banks" );
Expand Down
Loading