Spring DAO rewritebatched语句在具有EmbeddedId的实体上的SaveAll()上不起作用

问题描述 投票:0回答:1

我们需要在mysql上快速插入500万条记录(对此实例无控制权。)>

下面尝试了所有,但没有任何效果:

  1. 设置rewritebatchedstatements=true(通过url和props)
  2. 尝试过useServerPrepStmts=trueuseServerPrepStmts=true
  3. 尝试过以下其他冬眠道具
  4. [StoryGenerationType.Auto,所以还可以,但是TaskEmbeddedId,所以批处理应该起作用? (因为未指定任何世代)
  5. 尝试过MySql5InnoDBDialectMySql5DBDialect
  6. 分批正在工作(基于统计信息),但rewritebatchedstatements无法工作。

spring.jpa.properties.hibernate.jdbc.batch_size=500
spring.jpa.properties.hibernate.jdbc.fetch_size=500
spring.jpa.properties.hibernate.jdbc.order_inserts=500
spring.jpa.properties.hibernate.jdbc.order_updates=500

spring.jpa.properties.hibernate.batch_versioned_data=true
spring.jpa.properties.hibernate.generate_statistics=true

spring.datasource.hikari.data-source-properties.rewriteBatchedStatements=true
#spring.datasource.hikari.data-source-properties.useServerPrepStmts=true
spring.datasource.hikari.data-source-properties.useServerPrepStmts=false

示例实体:

class SprintService {

   @Transactional
    public void startSprint(Epic epic, List<Stories> stories) {
        epic.save()
        .....
        stories.saveAll() // few hundreds of records
        Set<Task> tasks = new HashSet<>;
        for(Story story: stories)
        {
            tasks.addAll(story.getTasks());
            tasks.addAll(story.getTasks());
            tasks.addAll(story.getTasks());
            //do something
        }
        tasks.saveAll() // few million records
    }
}

@Table(name = "STORY")
@EqualsAndHashCode
class Story {
   @Id
   @GeneratedValue(stratergy=GenerationType.Auto)
   @Column(name="STORY_ID")
   Long id;

   @Column(name="STORY_NAME")
   String name;

   @OneToMany(cascade=MERGE, mappedBy="story", fetch = FetchType.Lazy)
   Set<Task> task;
}



@Entity
@Table(name = "TASK_XREF")
class Task {
    @EmbeddedId
    TaskPKId taskPKId;

    @Column(name = "TASK_NAME")
    String name;
    @MapsId("storyId")
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "STORY_ID")
    Story story;

    //getters, setters

}

这是TaskPKID类:

@Embeddable
class TaskPKId  implements Serializable {
        long taskId;
        long taskTypeId;
        @Column(name="STORY_ID")
        long storyId;

    public long getTaskId() {
        return taskId;
    }

    public void setTaskId(long taskId) {
        this.taskId = taskId;
    }

    public void setTaskTypeId(long taskTypeId) {
        this.taskTypeId = taskTypeId;
    }
}

我们需要在mysql上快速插入500万条记录(对此实例无控制)。尝试了所有以下内容,但没有任何效果:尝试设置rewritebatchedstatements = true(通过url和props)...

mysql hibernate spring-boot spring-data-jpa
1个回答
0
投票

值应为布尔值。

© www.soinside.com 2019 - 2024. All rights reserved.