[英]How can I verify hibernate.jdbc.batch_size is working?
在我的休眠属性中,我有<prop key =“ hibernate.jdbc.batch_size”> 30 </ prop>
在我的代码中,我做了类似的事情
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身份
尝试使用
@TableGenerator(name="TABLE_GEN", table="SEQUENCE_TABLE", pkColumnName="SEQ_NAME", valueColumnName="SEQ_COUNT", pkColumnValue="EMP_SEQ")
@GeneratedValue(strategy=GenerationType.TABLE, generator="TABLE_GEN")
您可以设置hibernate.generate_statistics = true并查找JDBC批处理上的统计信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.