You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JpaCursorItemReaderBuilder should have an option to set fetchSize, similar to HibernateCursorItemReader (which is deprecated) and JdbcCursorItemReaderBuilder.
Current Behavior
There is no option to fetch size for query executed by JpaCursorItemReader. As a workaround I created FetchSizeAwareJpaQueryProvider. Pasting here in case someone would like to use it:
importjakarta.persistence.EntityManager;
importjakarta.persistence.Query;
importorg.hibernate.jpa.AvailableHints;
importorg.springframework.batch.item.database.orm.JpaQueryProvider;
/** * {@link JpaQueryProvider} implementation that enables setting "FETCH_SIZE" query hint on the JPA query. * * <a href="https://jdbc.postgresql.org/documentation/query/#getting-results-based-on-a-cursor">Getting results based on a cursor</a> * * @author Maciej Walkowiak */publicclassFetchSizeAwareJpaQueryProviderimplementsJpaQueryProvider {
privatefinalStringqueryString;
privatefinalintfetchSize;
privateEntityManagerentityManager;
publicFetchSizeAwareJpaQueryProvider(StringqueryString, intfetchSize) {
this.fetchSize = fetchSize;
this.queryString = queryString;
}
@OverridepublicQuerycreateQuery() {
Queryquery = this.entityManager.createQuery(queryString);
query.setHint(AvailableHints.HINT_FETCH_SIZE, fetchSize);
returnquery;
}
@OverridepublicvoidsetEntityManager(EntityManagerentityManager) {
this.entityManager = entityManager;
}
}
Thank you for raising this, @maciejwalkowiak ! Support for query hints is indeed missing in JpaCursorItemReader and JpaPagingItemReader as well. Query hints should be set on the query just like query parameters. Respective builders should be updated as well.
I will plan this for v5.2 (the upcoming v5.1 is in feature freeze at this point). Contributions are welcome!
Enhanced `JpaCursorItemReader`, `JpaCursorItemReaderBuilder`,
`JpaPagingItemReader`, and `JpaPagingItemReaderBuilder` with
query hints configuration. The inclusion of query hints in both
cursor and paging item readers improves query execution strategies,
optimizing performance for complex data retrieval scenarios.
Resolvesspring-projects#4479
Signed-off-by: Fabrice Bibonne <fabrice.bibonne@gmail.com>
Expected Behavior
JpaCursorItemReaderBuilder
should have an option to setfetchSize
, similar toHibernateCursorItemReader
(which is deprecated) andJdbcCursorItemReaderBuilder
.Current Behavior
There is no option to fetch size for query executed by
JpaCursorItemReader
. As a workaround I createdFetchSizeAwareJpaQueryProvider
. Pasting here in case someone would like to use it:.. and use it like this:
If it makes sense I can see if I find time to contribute it.
The text was updated successfully, but these errors were encountered: