Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleJpaRepository.findAllById doesn't join eager fetched columns [DATAJPA-1721] #2016

spring-projects-issues opened this issue May 5, 2020 · 1 comment
in: core Issues in core support type: enhancement A general enhancement


Copy link

cda opened DATAJPA-1721 and commented

Using SimpleJpaRepository.findById(ID is) results in a query with left outer joins for each eager relationship.

Using SimpleJpaRepository.findAllById(Iterable ids) results in a query that fetches current entity columns and additional select queries for each eager relationship.

The performance of findAllById is affected by the additional select queries. Ideally it should generate the same query as findById but with id in () instead of id = .

SimpleJpaRepository.findAllById(Iterable ids) is generating a JPQL query to fetch entities and reading Vlad Mihalcea article it seems that using JPQL to fetch entities uses a different fetching strategy than entitymanager.find that results in additional selects

No further details from DATAJPA-1721

Copy link

cda commented

Workaround with hibernate method works as expected. It generates a single query.

entityManager.unwrap( Session.class )
    .byMultipleIds( MyEntity.class )
    .multiLoad( ids )

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core support labels Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core Issues in core support type: enhancement A general enhancement
None yet

No branches or pull requests

2 participants