время ответа результата очень велико, как уменьшить его при использовании jpa?

#spring-data-jpa

#spring-data-jpa

Вопрос:

 @Entity
    @Table(name = "demo")
    public class DemoEntity {

    @ElementCollection
    @Column(name = "demo_type_id", nullable = false)
    @CollectionTable(name = "demo_entity_record_type", joinColumns = @JoinColumn(name = 
"demo_entity_id"))
    private Set<RecordType> recordTypes = new HashSet<>();

    @ElementCollection
    @Column(name = "demo_type_id", nullable = false)
    @CollectionTable(name = "demo_entity_record_type1", joinColumns = @JoinColumn(name = 
"demo_entity_id"))
    private Set<DemoType> demoTypes1 = new HashSet<>();

    @ElementCollection
    @Column(name = "demo_type_id", nullable = false)
    @CollectionTable(name = "demo_entity_record_type2", joinColumns = @JoinColumn(name = 
"demo_entity_id"))
    private Set<RecorType> recordTypes2 = new HashSet<>();
    }
 

У меня 3000 записей сущности в БД. Когда я пытаюсь получить 3000 объектов, которые я вижу в журналах:

 3000 select to entity table
3000 select to test_entity_record_type table by test_entity_id
3000 select to test_entity_record_type1 table by test_entity_id
3000 select to test_entity_record_type2 table by test_entity_id
 

В результате время ответа очень велико. Как его уменьшить?

Ответ №1:

Вы можете использовать аннотацию @BatchSize:

 @BatchSize(size = 1000)
private Set<RecordType> recordTypes = new HashSet<>();
 

Дайте мне знать, если это сработает.