Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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
Spring 休眠批处理_Spring_Hibernate_Spring Boot_Batch Processing - Fatal编程技术网

Spring 休眠批处理

Spring 休眠批处理,spring,hibernate,spring-boot,batch-processing,Spring,Hibernate,Spring Boot,Batch Processing,因此,我尝试配置Hibernate以进行批处理。我已经构建了一个示例应用程序,并根据Hibernates文档进行了配置 但是在配置Hibernate注销SQL之后,看起来它根本没有执行批插入,而只是执行单个插入。我看错这日志了吗 因此,我在Spring Boot应用程序中配置了以下属性 spring.jpa.properties.hibernate.jdbc.batch_size=10 spring.jpa.properties.hibernate.show_sql=true spring.jp

因此,我尝试配置Hibernate以进行批处理。我已经构建了一个示例应用程序,并根据Hibernates文档进行了配置

但是在配置Hibernate注销SQL之后,看起来它根本没有执行批插入,而只是执行单个插入。我看错这日志了吗

因此,我在Spring Boot应用程序中配置了以下属性

spring.jpa.properties.hibernate.jdbc.batch_size=10
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true
这是我最基本的批处理编写器

@Transactional
公共类批处理编写器{

private EntityManager entityManager;

private int batchSize;

public BatchWriter(EntityManager entityManager, int batchSize) {
    this.entityManager = entityManager;
    this.batchSize = batchSize;
}

public void writeBatchOfCustomers(int numOf) {
    for(long i = 0; i <= numOf; i++) {
        Customer customer = new Customer(i);
        entityManager.persist(customer);

        if ( i % batchSize == 0 ) { //20, same as the JDBC batch size
            //flush a batch of inserts and release memory:
            entityManager.flush();
            entityManager.clear();
        }
    }
}
我错过了什么

它目前正在H2数据库中使用Spring Boot自动配置。不过,我最终会在Spring Batch和Oracle db中使用它,它将插入大约30k个对象和大约35个属性

谢谢你的帮助


谢谢,

所以hibernate SQL日志记录似乎有误导性(在我看来)

我的配置实际上是批处理

我为此类添加了一个具有调试级别的记录器:

org.hibernate.engine.jdbc.batch.internal.BatchingBatch

与Hibernate 5.0.12版中的当前名称相同(请认为它以前的名称是其他名称)


在这个类中,您可以看到它实际上是批处理。

为什么在配置JPA时使用普通的SessioNFactory?您应该使用
EntityManager
而不是
SessioNFactory
。因为从hibernate文档中复制的代码已经足够多了,所以它只是被扔掉了。我没有看到任何影响?您再次是co配置JPA,但使用的是普通的
会话工厂
。您正在配置X,但使用的是Y。为什么您认为配置X会影响Y。如上所述,使用
实体管理器
(只需将其插入到编写器中)并用
@Transactional
注释该类。删除所有Hibernate配置,让Spring Boot为您配置JPA。我使用的是原始代码段。但我正在从配置中配置的JPA EntityManagerFactory中解包会话。因此,尽管毫无意义,但它不会影响结果。无论如何,我已经更改了它使用JPA。为什么您自己配置JPA,使
application.properties
中的任何内容都变得毫无意义。
Hibernate: 
insert 
into
    customer
    (first_name, last_name, id) 
values
    (?, ?, ?)