[英]JPA repository findAll() limit
Hi I just wanted to know is there any limit for retrieving row from MYSQL database using JPARepository.findAll(), I have around 3700000 entries in my database.嗨,我只是想知道使用 JPARepository.findAll() 从 MYSQL 数据库中检索行是否有任何限制,我的数据库中有大约 3700000 个条目。 If I use findAll() do I get all the entries or truncated count?
如果我使用 findAll() 我会得到所有条目还是截断计数?
You will receive all entities until something breaks.您将收到所有实体,直到出现问题。
Things that might break:可能会破坏的事情:
As a rule of thumb: Never plan to have millions of JPA entities in memory.根据经验:永远不要计划在 memory 中拥有数百万个 JPA 实体。 Either process them in batches using pagination as Jimmy proposed.
或者按照Jimmy的建议使用分页分批处理它们。 Or use some other technology that scales better, eg
JdbcTemplate
and one of it's query
methods taking a RowCallbackHandler
或者使用其他一些可以更好地扩展的技术,例如
JdbcTemplate
和其中一个采用RowCallbackHandler
的query
方法
It is better to not use findAll if there are a lot of entities.如果有很多实体,最好不要使用 findAll。 You can use pagination something like, ( taking no of records in single page as SIZE ):
您可以使用类似的分页(将单页中的记录数作为SIZE ):
Pageable pageable = PageRequest.of(0, SIZE); // for example SIZE = 500
Page<Qmail> page = repository.findAll(pageable);
while (!page.isEmpty()) {
pageable = pageable.next();
// TODO WITH ENTITIES
page.forEach( entity -> SOP(entity.getId()) );
page = repository.findAll(pageable);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.