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

Using Pageable and EntityGraph, entire collection is loaded from database [DATAJPA-1677] #1976

Closed
spring-projects-issues opened this issue Feb 8, 2020 · 5 comments
Assignees
Labels
in: core Issues in core support status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue type: bug A general bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Feb 8, 2020

Christoffer opened DATAJPA-1677 and commented

I noticed some weird behavior when I added an EntityGraph to my findAll repository method:

  • When I use an EntityGraph, that specifies an attribute node on a field that uses a @OneToMany relationship, the entire collection will be loaded from the database (however, the Page object only contains my 25 limit objects).

  • No limit is added to the SQL statement

  • The number of rows loaded ~= playlists + items (which I believe should be ~= 25 + items)

  • The same thing does not happen if I add a @OneToOne or @ManyToOne field to my attribute nodes.

    • The limit (25) is then added as expected to the SQL statement
    • The number of rows loaded = 25

 

Highly simplified code from my project:

 

@Entity
@NamedEntityGraph(
        name = "graph",
        attributeNodes = {
                @NamedAttributeNode(value = "items")
        }
)
public class Playlist {

    ....
    @OneToMany(mappedBy = "playlist")
    private Set<Item> items;
}

 

 

interface PlaylistAdminRepository extends JpaRepository<Playlist, Integer>, JpaSpecificationExecutor<Playlist> {
    @EntityGraph(value = "graph")
    Page<Playlist> findAll(Pageable pageable);
}

 

 


Affects: 2.2.4 (Moore SR4)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 10, 2020

Jens Schauder commented

Could you please provide a reproducer for this?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 25, 2020

Michał Stochmal commented

That's completely normal behavior - JPA provider will fetch whole set of data and then paginate it in memory when @OneToMany children records are fetched within single query. To overcome this problem use native query or fetch children records after fetching page of data.

 

Check out this blog post:

https://vladmihalcea.com/fix-hibernate-hhh000104-entity-fetch-pagination-warning-message/

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 3, 2020

Suman Guduru commented

i'm also having same issue with entity graph 

@spring-projects-issues spring-projects-issues added status: waiting-for-feedback We need additional information before we can continue type: bug A general bug in: core Issues in core support labels Dec 30, 2020
@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 6, 2021

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Jan 6, 2021
@schauder
Copy link
Contributor

@schauder schauder commented Jan 7, 2021

As described by Michael Stochmal this is normal JPA behavior.

@schauder schauder closed this as completed Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants