表> 200列的JPARepository findAllById性能问题

时间:2019-07-30 09:04:33

标签: hibernate spring-boot spring-data-jpa

场景:

应用程序:Springboot,

数据库:MSSQL

表名称:帐户

列数:255

行数:5,00,000

主键(复合):ApplicationNumber,AccountNumber

问题:

当我们使用JPARepository.findAllById(AccountsPk pk)查询传入EmbeddedId的表时,它花费了超过1分钟的时间。

  1. 我已启用show-sql = true并直接在SQLServerManagementStudio中执行生成的sql,并且可以在1秒内获得结果。
  2. 使用EntityManager,我可以在<3秒内获得结果。

已用时间:<3秒 示例代码:

EntityManager em;
....
...
Query q= em.createQuery(select a from Accounts where a where a.id.accountNumber='xxx' and a.id.applicationNumber='YYYY') ;

List<Accounts> accounts = q.getResultList();
em.close;

与使用entitymanager相比,表具有更多的列/数据时,JpaRepository是否存在任何已知的性能下降限制?

0 个答案:

没有答案