3

I have two resources defined using a PagingAndSortingRepository:

  • galleries/{id}
  • images/{id}

Paging in general for both resources is available by the used repository type.

The gallery itself contains a list of images

@Entity
@Table(name = "Gallery")
public class Gallery extends AbstractEntity {

    private String name;

    @OneToMany(fetch = FetchType.EAGER)
    private List<Image> images;
    ...
}

I can now access the images of a gallery via

  • galleries/1/images

Is it possible to enable paging also for these sub-lists? or what is the REST style for handling those large lists.

thank you in advance, Guido

Guido
  • 33
  • 3

2 Answers2

1

If you make a findByGalleryId query on the images repository, it should return you the results paged. However, I don't understand why the sub-list you're querying isn't paged. Are you sure it has enough records for paging?

Andres
  • 10,561
  • 4
  • 45
  • 63
  • Hi Andres, thanks for your answer. The findByGalleryId is not possible, as the image does not have a gallery id. The link is done by a link table. That's a semantic issue. An image does not necessarily belong to a gallery. I will test to increase the number of images, but I would expect to have a page entry with a totalCount value in any case in order to not need a different handling in the frontend for both cases. – Guido Jan 12 '14 at 12:14
0

Related to my question here: Spring Data Rest Pageable Child Collection

So far I've been unable to get the collections inside of an object to page the way you describe. I ended up basically doing as Andres suggested.

You can implement a finder on images to return a page and then use @RestResource(exported=false) to hide the link from the gallery side.

Community
  • 1
  • 1
Ethan Anderson
  • 628
  • 1
  • 10
  • 20