When I call custom method in PagingAndSortingRepository with Pageable object set to page > 0 the generated statement has misplaced first and skip parameters (They are inserted by Spring + Hibernate) so I do not have any control over them.
Example:
— Controller
Pageable paging = PageRequest.of(1, 10);
Page<MaterialBrand> items = repository.findByMaterialSizesQuery(25, paging);
— Repository
@Query(
value = "select t_m_gatunki.id...... where gmin <= :value AND gmax >= :value",
nativeQuery = true
)
Page<MaterialBrand> findByMaterialSizesQuery(@Param("value") Float value, Pageable pageable);
Log output:
Hibernate:
select
skip ? first ? t_m_gatunki.id,….
Which results in Error:
There was an unexpected error (type=Internal Server Error, status=500).
could not prepare statement [Dynamic SQL Error; SQL error code = -104; Token unknown – line 1, column 21; ? [SQLState:42000, ISC error code:335544634]]
Certainly properly generated statement should look like this
Hibernate:
select
first ? skip ? t_m_gatunki.id,….
I have to add that when I use standard methods e.g repository.findAll(paging) everything is OK and first and skip are at proper positions.
Hoping for any solutions.
Tried to leverage runtimeOnly ‘org.firebirdsql.jdbc:jaybird:5.0.4.java11’. Tried to implemet QueryRewriter with Repository but the query in rewrite method is still not prepared statement so no effect.
Zadra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.