I have a query in mind that requires pagination and I want to build it with Spring JPA. I have 3 tables, detail, header, and claim. A header record can have many (children) detail records and has a OneToMany mapping. A claim has no relationship to header but both have this field claim_num (not the primary key) that is the same value though there are no formal constraints. Claim also has a field 'lastName' I would like to sort by. In a detail repo extending Spring's JPARespository, I had built a method with @Query with the following:
@Query("select new MyDTO(d, h, c) from Detail d, Header h
left join Claim c on h.claimNum = c.claimNum")
Page<MyDTO> getSomeDetails( new Page(0, 10, new Sort("claim.lastName" ) ))
The goal is to get pages of details and values from header and claim need to be returned in the result set as well. The order by is my current impediment. I am getting 'claim is not a property of detail'. That makes sense but detail formally relates to header but to claim nothing is mapped. How can the generated SQL get the 'order by' correct when passing in Page(Sort()) at the detail level? Thanks for reading and any help is appreciated. This is spring boot but upgraded to hibernate-core 5.1.