简体   繁体   English

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

[英]How can I verify hibernate.jdbc.batch_size is working?

In my hibernate properties I have <prop key="hibernate.jdbc.batch_size">30</prop> 在我的休眠属性中,我有<prop key =“ hibernate.jdbc.batch_size”> 30 </ prop>

In my code I do something similar to 在我的代码中,我做了类似的事情

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();
}

My Pojo has the following 我的Pojo具有以下内容

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

However, When I change the batch size it doesn't seem to affect the overall run time. 但是,当我更改批次大小时,它似乎并没有影响整体运行时间。 How can I verify that it is in fact working? 我如何验证它确实在工作?

Thanks! 谢谢!

comment out session.flush(); 注释掉session.flush(); and see if anything is inserted after 20 loop interations 看看20次循环插入后是否插入了任何东西

Update: to the updated question 更新:更新后的问题

commenting //@GeneratedValue(strategy = GenerationType.AUTO) should fall back to default which is AFAIK Identity 评论//@GeneratedValue(strategy = GenerationType.AUTO)应该退回到默认值,即AFAIK身份

try using 尝试使用

@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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM