[英]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.