Java 8 JPA Repository Stream row-by-row in Postgresql Java 8 JPA Repository Stream row-by-row in Postgresql postgresql postgresql

Java 8 JPA Repository Stream row-by-row in Postgresql


Its PostgreSQL equivalent is:

@QueryHints(value = @QueryHint(name = HINT_FETCH_SIZE, value = "1")

For contrast setFetchSize(rows) should throw SQLException when the condition rows >= 0 is not satisfied. This is not honored by MySQL's JDBC driver.

Though in PostgreSQL you can actually set up values greater than 1 to allow some caching by PostgreSQL's JDBC driver. The docs' example of 50 seems reasonable (unless you have irrationally wide rows). You could also choose this value to be a portion of the expected row count. Test a few variants before deploying your application.