简体   繁体   中英

JPA repository - improve findAll() performances

I am using JPA repository, I need to retrieve a whole Mysql table(40000 records) wich has 5 foreign keys towards smaller tables (500 records). I need one field of each of these 5 tables.

If I call a JPArepository findall() , it takes a few seconds to retrieve all the data.

I need it to be faster. Is there a way to do that?

I don't know what would be the best solution, if it can be done on mysql side, or must be done on Java side. All the tables are well mapped to JPA entities :

@Entity
    @Table(name = "T_CLIENT")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    public class Client implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "code")
    private String code;

    @OneToOne
    private Seller seller;

    @OneToOne
    private Language language;

    @OneToOne
    private Address address;

    @OneToOne
    private Country billCountry;

    @OneToOne
    private ClientType clientType;
}

Thank you for your answers.

您可以使用EntityGraph机制从外键表中选择加载字段。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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