如何解决答案的结果时间很长,如何在使用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
结果回答时间很长。如何减少?
解决方法
你可以使用@BatchSize注解:
@BatchSize(size = 1000)
private Set<RecordType> recordTypes = new HashSet<>();
让我知道这是否有效。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。