当前位置: 首页 > 知识库问答 >
问题:

Spring Boot和Spring Data JPA不工作时的大容量插入

狄侯林
2023-03-14

我试图配置Spring Boot和Spring Data JPA,以便在批处理中进行批量插入。

目标是:在执行repository.save()操作时,提交每个n-记录,而不是每个记录。

从现在起,我在application.properties中尝试了:

spring.jpa.properties.hibernate.jdbc.batch_size=100
spring.jpa.properties.hibernate.order_inserts=true
spring.jpa.properties.hibernate.order_updates=true
spring.jpa.properties.hibernate.generate_statistics=true
@Component
public class BulkInsert {

    @Autowired
    MyRepository repository;

    public void process() {

        PodamFactory podamFactory = new PodamFactoryImpl();

        for(int i=0;i<10000;i++) {
            MyEntity myEntity = podamFactory.manufacturePojo(MyEntity.class);
            repository.save(myEntity);
        }

    }
}

以下是实体:

@Entity
@Table(name="MYTABLE")
@NamedQuery(name="MyEntity.findAll", query="SELECT m FROM MyEntity m")
public class MyEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    @Column(name="DESCRIPTION")
    private String description;

    @Id
    @Column(name="ID")
    private String id;

    public MyEntity() {
    }

    // getters and setters

}

和存储库:

public interface MyRepository extends CrudRepository<MyEntity, String> {

}

共有1个答案

周峻
2023-03-14

在我的例子中,即使使用这些配置,大容量插入也不起作用。

结果表明,如果实体使用generationtype.identity标识符生成器,Hibernate将静默禁用批插入/更新。

也许这会帮助别人。

    null
 类似资料:
  • 我无法使用C#webapi将大量数据插入AzureSQL服务器DB 考虑考虑 我想插入60K 我的方法:(都在本地sql server中工作,但不在Azure sql server中工作) 1) 尝试使用EF逐个插入记录(10000次约10分钟,大部分超时) 2) 尝试使用大容量插入扩展以及在SqlBulkCopy中尝试的EF 3) 4) 尝试增加连接字符串中的连接超时 5) 尝试在Dbconte

  • 我在我的模型中使用LocalDateTime,在包括LocalDateTimeDeserializer之后,将bean字段转换为 包括 属性在SpringBoot的应用程序中。属性文件,应用程序最终能够反序列化JSON并正确显示如下内容:, 但是,当我进行测试时,它会忽略WRITE_DATES_AS_TIMESTAMPS标志,我猜它会为上面相同的字符串日期生成一个输出, 请注意,在测试资源文件夹中

  • controller.java UserServiceImpl.java 我得到了这个错误 应用程序启动失败 描述: 我使用的SpringBoot版本:2.1.0.发行版

  • 我正在学习Spring Boot来构建应用程序。我试图用不同包中的控制器作为应用程序来构建我的第一个Spring Boot应用程序。Tomcat实例出现,但请求没有到达为URI注册的RestController。 以下是控制器类: 以下是应用程序类: Pom.xml tomcat启动时的日志: 我添加了基本包扫描,甚至尝试了注释,但当我点击URL(http://localhost:8080/abc

  • 我想在我的sql-server数据库中插入。txt文件数据。我在.txt文件中使用和不使用PK-Variable时都出现了错误。我的疑问: 使用 从“C:\user\test.txt”大容量插入db.schema.table(FIELDTERMINATOR=';')去吧 null null

  • 我有一个Springboot应用程序,我的实体模型与作为依赖项包含的主应用程序分开。 我的Application.java位于此包中 我的实体模型位于这个包com.a.b中的另一个项目中 但是我得到一个错误:由:java.lang.IllegalArgumentException:不是托管类型:类引起