gpt4 book ai didi

java - 如何验证 hibernate.jdbc.batch_size 是否正常工作?

转载 作者:行者123 更新时间:2023-11-30 11:48:16 25 4
gpt4 key购买 nike

在我的 hibernate 属性中 30

在我的代码中我做了类似的事情

final StatelessSession sSession = sessionFactory.openStatelessSession();
try {
sSession.connection().setAutoCommit(false);
} catch (final SQLException se) {
// log a message
}
final Transaction tx = sSession.beginTransaction();
try{
for ( some loop ) {
Customer customer = new Customer(.....);
sSession.insert(customer);
/* Do we need to flush a stateless session? It doesn't have methods for it
if ( i % 30 == 0 ) { //30, same as the JDBC batch size
//flush a batch of inserts and release memory:
sSession.flush();
sSession.clear();
}
*/
}
//sSession.flush();// Do we need to flush a stateless session? It doesn't have methods for it
//sSession.clear();
} finally{
tx.commit();
sSession.close();
}

我的 Pojo 有以下内容

@Id
//@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID", nullable = false, unique = true)
private Long id;

但是,当我更改批处理大小时,它似乎不会影响整体运行时间。我如何验证它是否确实有效?

谢谢!

最佳答案

注释掉 session.flush(); 并查看在 20 次循环交互后是否插入了任何内容

更新:更新问题

评论 //@GeneratedValue(strategy = GenerationType.AUTO) 应该回退到默认值,即 AFAIK Identity

尝试使用

@TableGenerator(name="TABLE_GEN", table="SEQUENCE_TABLE", pkColumnName="SEQ_NAME", valueColumnName="SEQ_COUNT", pkColumnValue="EMP_SEQ")
@GeneratedValue(strategy=GenerationType.TABLE, generator="TABLE_GEN")

关于java - 如何验证 hibernate.jdbc.batch_size 是否正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8925940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com