Skip to content

When using findAll with Specification and Pageable as parameters and using the map method on the returned Page, a OneToMany full table load is caused. #4046

@zhaoops

Description

@zhaoops

@Entity
@Data
@DynamicInsert
@DynamicUpdate
@Table(name = "meta_album")
@EqualsAndHashCode(callSuper = true)
public class MetaAlbum extends PrimaryPk {

    ....    

    @OneToMany(mappedBy = "metaAlbum")
    @Fetch(FetchMode.SUBSELECT)
    private List<MetaSong> metaSongs = new ArrayList<>();

    ....    

}

Service

Specification<MetaAlbum> spec = buildSpecification(query);
Page<MetaAlbum> albums = metaAlbumRepository.findAll(spec, pageable);
return albums.map(this::convertToListDTO);

log(Not expected)

Hibernate: 
    select
        ....
    from
        meta_song metasongs0_ 
    where
        metasongs0_.album_id in (
            select
                metaalbum0_.id 
            from
                meta_album metaalbum0_ 
            where
                metaalbum0_.release_date>=? 
        )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions