I have an @Entity called User. It has a Set of Changesets as follows:
@OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="user")
private Set<Changeset> changesets = new HashSet<Changeset>();
I have a UserRepository:
@Repository
@RestResource(path = "users", rel = "users")
public interface UserRepository extends JpaRepository<User, Long>{ }
And a ChangesetRepository:
@Repository
@RestResource(path = "changesets", rel = "changesets")
public interface ChangesetRepository extends JpaRepository<Changeset, Long> { }
Calling GET on http://localhost:8080/changesets/
or http://localhost:8080/users/
yields a paged response.
If I call GET on http://localhost:8080/users/1/changesets
then I get all the results in a single array and no paging occurs.
Is there a way to indicate to Spring Data Rest that I want to return the changesets collection in a pageable manner when accessing it through its parent User? The Set of changesets will grow quickly and I'd rather not return tons of results in a single page.
EDIT:
As suggested by Willie Wheeler I added this to my ChangesetRepository to make it searchable:
@RestResource(path = "byUser", rel = "byUser")
public Page<Changeset> findByUser(@Param("id") User user, Pageable p);
I left the relationship bidirectional, but was also able to hide the link to changesets from a user by using @RestResource(exported=false)
on the Set of changesets.
Side Note: It appears that setting the relationship to exported=false hides the link, but doesn't actually remove the mapping. /users/1/changesets isn't advertised, but it's still valid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With