0

I am writing a native query that collects data from several tables. I also need pageable and sort by alliances. Unfortunately, Sort "sticks" immediately the address of the first table that has no given alliance. Is it possible to dynamically sort and also page? I tried to pass a String with a name followed by "order by", but hibernate ignores it.

@Query(value = "SELECT pt.id as id, pt.work as workplace ,bo.virtualName as title, bo.creationDate as date FROM t_projecttemplate pt JOIN t_objecttowork ot on pt.id=ot.id JOIN t_objectplus bo on ot.id=bo.id where bo.deleted=false and bo.parent_id=?1", nativeQuery = true)
List<Map<String,Object>> getObjects (Long parentId, Pageable pageable); //want to sort by title, hibernate sticks immediately "pt."
xampo
  • 369
  • 1
  • 7
  • 22

1 Answers1

0

When you call getObjects and pass Pageable to it (e.g. PageRequest), it has a sort parameter. So you can create something like:

Pageable myPage = PageRequest.of(0, 10, Sort.Direction.ASC, "title");
getObjects(parentId, myPage);
Dmitrii Bocharov
  • 872
  • 6
  • 21
  • This is how Pageabel is created and as the title passes, in SQL it is appended "pt.title" (inside Pageable no) – xampo Mar 04 '20 at 22:06