Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何验证hibernate.jdbc.batch_大小是否正常?_Java_Hibernate_Spring - Fatal编程技术网

Java 如何验证hibernate.jdbc.batch_大小是否正常?

Java 如何验证hibernate.jdbc.batch_大小是否正常?,java,hibernate,spring,Java,Hibernate,Spring,在我的hibernate属性中 三十 在我的代码中,我做了类似于 final StatelessSession sSession = sessionFactory.openStatelessSession(); try { sSession.connection().setAutoCommit(false); } catch (final SQLException se) { // log a message } final Transaction tx = sSession.b

在我的hibernate属性中 三十

在我的代码中,我做了类似于

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)
应返回默认值,即AIK标识

试用

@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批处理的统计信息。

ok,则批处理不起作用。常见的情况是,如果使用“标识”或“本机”id生成器,则Hibernate必须在save()上立即转到db以获取id。正确,我没有标识集。请参阅主要帖子中的更新代码。我应该注意,我目前正在手动设置ID,因此不需要“策略”。我不知道这是否会影响禁用批处理或不设置此选项后,我“认为”批处理开始生效。我看到30年的运行时间很糟糕,但300年和3000年的运行时间与没有批处理的运行时间相同。有没有可能,你知道如何在不随机测试成吨的情况下确定最佳批号?谢谢我通常会选择100、300或1000,但最好的方法是分析它