I would like to understand why my custom query returns either a Mixed Parameter Strategies Exception or a Column... Not Found in ORDER BY... (when removing pageable below).
// I need to use this request in order to return screenshots that matches tags (2 is hard coded for now).
@Query(value = "SELECT * FROM screens_tags st INNER JOIN screens ON screens.id = st.screen_id INNER JOIN tags ON tags.id = st.tag_id WHERE tags.name IN (:tags) GROUP BY st.screen_id HAVING COUNT(*) = 2 ORDER BY ?#{#pageable}", nativeQuery = true)
Page<Screen> findDistinctByTagsIn(@Param("tags") List<String> tags, Pageable pageable);
For now unfortunately i can't figure out how to get ride of any of those errors, but I think it might come from the sort I am using with my controller.
@GetMapping("/screens")
public Page<Screen> getScreensWithPagination(
@RequestParam(name = "page", defaultValue = "0") int numPage,
@RequestParam(name = "sort", defaultValue = "created") String sort,
@RequestParam(name = "direction", defaultValue = "ASC") String direction,
@RequestParam(name = "tags", defaultValue = "") List<String> tags) {
Pageable pageable = PageRequest.of(numPage, NB_SCREEN_PER_PAGE, Sort.Direction.fromString(direction), sort);
return screenService.retrieveScreens(pageable, tags);
}
Because when I get ride of the ORDER BY ?#{#pageable} it tries to order it with an unknown column called 'created' (although it exists in the screens table). Otherwise, it tries to tell me something I cannot understand yet (mixed parameters strategies...).
Any help appreciated!
Scenario (for context only) : Let's say for the example I use a list of two tags for my query : ('Scythe', 'Game'). The first screenshot has multiple tags (whatever they are) and particularly the Scythe tag. The other screenshot has the Scythe and Game tag (between maybe other tags), which means the second screenshot and only this one must definitely pop in the results.
All of the above, tried to figure out with different parameters, in vain. Expecting the query to return a result instead of throwing an error.