Java 8 JPA存储库流在Postgresql中逐行 [英] Java 8 JPA Repository Stream row-by-row in Postgresql
问题描述
阅读此定义了必需所必需的某些查询提示( @QueryHints
批注),以使MySQL处理结果集逐行显示。有谁知道PostgreSQL需要什么(如果有的话)?
Reading this about MySQL defines certain query hints (@QueryHints
annotation) that are required in order to make MySQL process the result set row-by-row. Does anyone know for sure what (if anything) is required for PostgreSQL?
这是MySQL存储库中的引用查询定义:
Here is the reference query definition in the repository for MySQL:
@QueryHints(value = @QueryHint(name = HINT_FETCH_SIZE, value = "" + Integer.MIN_VALUE))
@Query(value = "select t from Todo t")
Stream<Todo> streamAll();
推荐答案
相当于PostgreSQL的是:
Its PostgreSQL equivalent is:
@QueryHints(value = @QueryHint(name = HINT_FETCH_SIZE, value = "1")
对比 setFetchSize(rows)
应该在时抛出 SQLException
条件行> = 0
不满足。MySQL的JDBC驱动程序不支持此条件。
For contrast setFetchSize(rows)
should throw SQLException
when the condition rows >= 0
is not satisfied. This is not honored by MySQL's JDBC driver.
尽管在PostgreSQL中,您实际上可以设置大于 1
的值,以允许PostgreSQL的JDBC驱动程序进行某些缓存。文档示例的 50
似乎是合理的(除非您有您也可以选择此值作为预期行数的一部分。在部署y之前测试一些变体我们的应用程序。
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.
这篇关于Java 8 JPA存储库流在Postgresql中逐行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!