I'm running a JPA non-native query, which returns a custom object.
@Query("""
SELECT
new path.to.CustomObject(
t,
(select id from users where name = :param1)
(select id from departments where name IN (:param2))
)
FROM timesheets t
WHERE status = :param3
)
Page<CustomObject> getAll(
@Param("param1") String param1,
@Param("param2") List<String> param2,
@Param("param3") String param3,
Pageable pageable
)
When I run the query with default pagination (size = 10, page = 0), the logger will print:
o.s.d.j.r.q.QueryParameterSetter$ErrorHandling: Silently ignoring
java.lang.IllegalArgumentException: Could not locate named parameter [param1], expecting one of [param3]
java.lang.IllegalArgumentException: Could not locate named parameter [param2], expecting one of [param3]
But the query runs just fine and will return me the correct values, including the ones from the subqueries. If I run the same query with more page size (size 30, page = 0) the query still runs fine and with no errors. If I add a simple where condition below, for example:
[...]
FROM timesheets t
WHERE status = :param3
AND :param1 = :param1
AND :param2 = :param2
The error will only raise for param2
because it's a List. It looks like the params used inside a subquery are ignored, but I can't understand why this simple trick doesn't also work for lists.
I would like to avoid printing "fake" exceptions in the logging (since they don't actually block the execution), so I'm looking for either a workaround (like putting them in an always-true WHERE condition) or a way to prevent Spring from logging the silently ignored exceptions.
You can use below property in your application.properties to suppress verbose parameter binding logs in Spring Data JPA.
This helps keep your logs clean by only showing errors during query parameter binding, which is especially useful in production environments.
logging.level.org.springframework.data.jpa.repository.query.QueryParameterSetter=ERROR