繁体   English   中英

JPA Spring-boot 与 Oracle 数据库的性能插入

[英]Performance insert by JPA Spring-boot with Oracle database

首先感谢您的时间。

我正在尝试通过 JPA(spring-boot) 将数据插入数据库,该项目正在使用Oracle

目前,插入 5000 条记录,使用repository.save(...)repository.saveAll(...)需要很长时间。

我尝试了batch_size ,但它不起作用(看起来它不适用于 oracle ?)。

代码配置:

            Properties properties = new Properties();
            properties.setProperty("hibernate.ddl-auto", "none");
            properties.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle12cDialect");
            properties.setProperty("hibernate.show_sql", "true");
            properties.put("hibernate.jdbc.batch_size", 5);
            properties.put("hibernate.order_inserts", true);
            properties.put("hibernate.order_updates", true);
            setJpaProperties(properties);

我创建 sql 查询以一次插入多行执行语句。

INSERT ALL INTO table(...)...

希望有更好更有效的方法

那么,你能给我任何解决方案吗?

太感谢了!!!!

怎么样:batch_size : 1000 当实体计数为 1000 时,然后 :repository.saveAndFlush(); 然后调用下一批。

另一种方法是在批量保存中直接调用EntityManagerpersist。 喜欢:

public int saveDemoEntities(List<DemoEntity> DemoEntities) {
    long start = System.currentTimeMillis();
    int count = 0;
    for (DemoEntities o : DemoEntities) {
        entityManager.persist(o);
        count++;
        if (count % BATCH_COUNT == 0) {
            entityManager.flush();
            entityManager.clear();
        }
    }
    entityManager.flush();
    entityManager.clear();
    return count;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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