I am working on an api and am trying to leverage @RepositoryRestResource to get paginated results. This works fine with a single entity and repository. When this entity has a @OneToMany/@ManyToOne bidirectional child, calls to the child endpoint do not return the page element. I made an example to demonstrate. Given the application:

@SpringBootApplication
public class NestedDataJpaApplication {
    public static void main(String[] args) {
        SpringApplication.run(NestedDataJpaApplication.class);
    }
}

My model objects:

@Entity
public class Company {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    private String name;

    public Long getId() {
     return id;
    }

    public String getName() {
     return name;
    }

    @OneToMany(targetEntity = Division.class, mappedBy = "company")
    private List<Division> divisions = new ArrayList<>();

    public List<Division> getDivisions() {
     return divisions;
    }
}

@Entity
public class Division {
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    private Long id;
    String name;

    @ManyToOne
    private Company company;

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public Company getCompany() {
        return company;
    }
}

And the resource repositories:

@RepositoryRestResource
public interface CompanyRepository extends PagingAndSortingRepository<Company, Long> {}

@RepositoryRestResource
public interface DivisionRepository extends PagingAndSortingRepository<Division, Long> {}
After starting the application, create a company with:
curl --location --request POST 'http://localhost:8080/companies' 
--header 'Content-Type: application/json' 
--data-raw '{
"name":"Microsoft"
}'

Now fetch the results to see the pagination info at the bottom:

curl --location --requestGET 'http://localhost:8080/companies'{
{
"_embedded" : {
"companies" : [ {
"name" : "Microsoft",
"_links" : {
"self" : {
"href" : "http://localhost:8080/companies/1"
},
"company" : {
"href" : "http://localhost:8080/companies/1"
},
"divisions" : {
"href" : "http://localhost:8080/companies/1/divisions"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/companies{?page,size,sort}",
"templated" : true
},
"profile" : {
"href" : "http://localhost:8080/profile/companies"
}
},
"page" : {
"size" : 20,
"totalElements" : 1,
"totalPages" : 1,
"number" : 0
}
}

Add a division:

curl --location --request POST 'http://localhost:8080/divisions' 
--header 'Content-Type: application/json' 
--data-raw '{
"name":"Windows",
"company":"http://localhost:8080/companies/1"
}'

Now when fetching divisions, note the missing page section:

curl --location --request GET 'http://localhost:8080/companies/1/divisions'

{
"_embedded" : {
"divisions" : [ {
"name" : "Windows",
"_links" : {
"self" : {
"href" : "http://localhost:8080/divisions/2"
},
"division" : {
"href" : "http://localhost:8080/divisions/2"
},
"company" : {
"href" : "http://localhost:8080/divisions/2/company"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/companies/1/divisions"
}
}
}

Expected behavior is the child element will have a page section just as the parent does.

Here is my build.gradle for good measure:

plugins {
    id 'org.springframework.boot' version '2.2.2.RELEASE'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    runtimeOnly 'com.h2database:h2'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

Comment From: sbrannen

@RepositoryRestResource is from the Spring Data REST project; whereas, this issue tracker is for the core Spring Framework.

Please open your issue in the issue tracker for Spring Data REST.

Thanks