Java hibernate.jdbc.fetch_size 和 hibernate.jdbc.batch_size 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21257819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between hibernate.jdbc.fetch_size and hibernate.jdbc.batch_size?
提问by Bhargav Kumar R
I am trying to tune my application, came across some blogs speaking about the batch fetch and batch select and putting my understanding as follows.
我正在尝试调整我的应用程序,遇到了一些关于批量获取和批量选择的博客,并将我的理解如下。
hibernate.jdbc.fetch_size
- Used to specify number of rows to be fetched in a select query.hibernate.jdbc.batch_size
- Used to specify number of inserts or updates to be carried out in a single database hit.
hibernate.jdbc.fetch_size
- 用于指定要在选择查询中获取的行数。hibernate.jdbc.batch_size
- 用于指定要在单个数据库命中中执行的插入或更新次数。
Please let me know whether my understanding is correct or not? Also what are the optimal valuesfor the above parameters..
请让我知道我的理解是否正确?还有上述参数的最佳值是什么..
采纳答案by Trevor Gowing
Both of these options set properties within the JDBC driver. In the first case, hibernate.jdbc.fetch_size
sets the statement's fetch size within the JDBC driver, that is the number of rows fetched when there is more than a one row result on select statements.
这两个选项都在 JDBC 驱动程序中设置属性。在第一种情况下,hibernate.jdbc.fetch_size
在 JDBC 驱动程序中设置语句的提取大小,即当 select 语句上有多个行结果时提取的行数。
In the second case, hibernate.jdbc.batch_size
determines the number of updates (inserts, updates and deletes) that are sent to the database at one time for execution. This parameter is necessary to do batch inserts, but must be coupled with the ordered inserts parameter and the JDBC driver's capability to rewrite the inserts into a batch insert statement.
在第二种情况下,hibernate.jdbc.batch_size
确定一次发送到数据库以供执行的更新(插入、更新和删除)次数。此参数是执行批量插入所必需的,但必须与有序插入参数和 JDBC 驱动程序将插入重写为批量插入语句的能力相结合。
See this link
看这个链接
回答by Saket
回答by jvdp
Your understanding seems quite correct. I would refer you to the JBOSS documentation on Hibernate, the following chapter is on Batch processing. And this one on tweaking performance.
你的理解似乎很正确。我会向您推荐有关 Hibernate 的 JBOSS 文档,以下章节是关于批处理的。而这个是关于调整性能的。
It's a good, easy to read source. It gives some suggestions on optimal values, but as CodeChimp mentioned, tuning is best done case by case and is a repeatable process over time.
这是一个很好的,易于阅读的源代码。它提供了一些关于最佳值的建议,但正如 CodeChimp 所提到的,调整最好是逐个进行,并且随着时间的推移是一个可重复的过程。
回答by Vlad Mihalcea
Your assumptions are correct.
你的假设是正确的。
hibernate.jdbc.fetch_size
hibernate.jdbc.fetch_size
The hibernate.jdbc.fetch_size
Hibernate configuration property is used for setting the JDBC Statement#setFetchSize
property for every statement that Hibernate uses during the currently running Persistence Context.
在hibernate.jdbc.fetch_size
Hibernate配置属性用于设置JDBCStatement#setFetchSize
属性,Hibernate对当前正在运行的持久化上下文中使用的每个语句。
Usually, you don't need to set this property as the default is fine, especially for MySQL and PostgreSQL which fetch the entire ResultSet
in a single database roundtrip. Because Hibernate traverses the entire ResultSet
, you are better off fetching all rows in a single shoot instead of using multiple roundtrips.
通常,您不需要设置此属性,因为默认值就可以了,特别是对于 MySQL 和 PostgreSQL,它们ResultSet
在单个数据库往返中获取整个。因为 Hibernate 遍历整个ResultSet
,所以最好在一次拍摄中获取所有行,而不是使用多次往返。
Only for Oracle you might want to set it since the default fetch size is just 10. For more details, check out this article.
仅对于 Oracle,您可能需要设置它,因为默认提取大小仅为 10。有关更多详细信息,请查看此文章。
hibernate.jdbc.batch_size
hibernate.jdbc.batch_size
The hibernate.jdbc.batch_size
property is used to batch multiple INSERT< UPDATE, and DELETE statements together so that they can be set in a single database call.
该hibernate.jdbc.batch_size
属性用于将多个 INSERT< UPDATE 和 DELETE 语句一起批处理,以便可以在单个数据库调用中设置它们。
If you set this property, you are better off setiing these two as well:
如果你设置了这个属性,你最好也设置这两个:
hibernate.order_inserts
totrue
hibernate.order_updates
totrue
hibernate.order_inserts
到true
hibernate.order_updates
到true
For more details check out these two articles:
欲了解更多详情,请查看这两篇文章: