#java #spring-boot #sorting #spring-data-jpa #pageable
#java #spring-boot #sorting #spring-data-jpa #pageable
Вопрос:
Я определил именованный собственный запрос в orm.xml который сопоставляется с методом, объявленным в интерфейсе репозитория
Хранилище для студентов
@Query(nativeQuery = true) public Listlt;DeptStuInfogt; deptEmplInfosPageable(Pageable pageable);
orm.xml
lt;named-native-query name="Student.deptEmplInfosPageable" result-set-mapping="DeptEmplMapping"gt; lt;querygt;lt;![CDATA[select dept.name as deptName,stu.name as stuName,stu.doj as stuDoj from department dept,student stu where dept.id=stu.studeptId group by dept.name,stu.name,stu.doj ]]gt; lt;/querygt; lt;/named-native-querygt; lt;named-native-query name="Student.deptEmplInfosPageable.count"gt; lt;querygt;lt;![CDATA[select count(1) from student stu]]gt;lt;/querygt; lt;/named-native-querygt; lt;sql-result-set-mapping name="DeptEmplMapping"gt; lt;constructor-result target-class="com.example.querydslex.pojo.DeptStuInfo"gt; lt;column name="deptName"/gt; lt;column name="stuName"/gt; lt;column name="stuDoj" class="java.time.LocalDate"/gt; lt;/constructor-resultgt; lt;/sql-result-set-mappinggt;
Результат сопоставляется с классом DeptStuInfo
public class DeptStuInfo { private String deptName; private String studentName; @JsonFormat(pattern = "dd-MM-yyyy") private LocalDate studentDoj; public String getDeptName() { return deptName; } public void setDeptName(String deptName) { this.deptName = deptName; } public String getStudentName() { return studentName; } public void setStudentName(String studentName) { this.studentName = studentName; } public LocalDate getStudentDoj() { return studentDoj; } public void setStudentDoj(LocalDate studentDoj) { this.studentDoj = studentDoj; } public DeptStuInfo(String deptName, String studentName, LocalDate studentDoj) { super(); this.deptName = deptName; this.studentName = studentName; this.studentDoj = studentDoj; } }
Я использую класс для установки объекта для просмотра страниц
public class PageablePojo { private Integer page; private Integer size; private String sort; private String direction; public Integer getPage() { return page; } public void setPage(Integer page) { this.page = page; } public Integer getSize() { return size; } public void setSize(Integer size) { this.size = size; } public String getSort() { return sort; } public void setSort(String sort) { this.sort = sort; } public String getDirection() { return direction; } public void setDirection(String direction) { this.direction = direction; } }
Using the above class to create the pageable object as below
PageRequest.of(obj.getPage(), obj.getSize(), Sort.by(obj.getSort()));
The issue I am facing is that order by clause is not generated in the query. Only limit clause is getting generated