Due to a binding issue it's not possible to mix a SpEL @Param and a String @Param on a Repository finder annotated with @Query if not all incoming parameters are used in SpEL syntax.
Example which fails:
@Query("FROM DataEntity de WHERE de.foo = :#{#spELValueObject.fooValue} AND de.bar = :barValue")
DataEntityfindByMixedParamsStringLast(@Param("spELValueObject") SpELValueObjectspELValueObject,
@Param("barValue") StringbarValue);
@Query("FROM DataEntity de WHERE de.foo = :#{#spELValueObject.fooValue} AND de.bar = :#{#barValue}")
DataEntityfindByMixedParamsStringLastPlusFakeSpEL(@Param("spELValueObject") SpELValueObjectspELValueObject,
@Param("barValue") StringbarValue);
The order of the params (SpEL first / SpEL last) does not matter
Affects: 2.0 M4 (Kay)
Issue Links:
DATAJPA-1103@Query method with mixed SpEL and simple binding failed
("is duplicated by")
DATAJPA-963 LIKE operator % in countQuery not working as expected
("is duplicated by")
Quick explanation for the QueryParameterSetter abstraction in the current PR and general overview (might eventually become the discussed wiki article).
For the binding a couple of choices have to be made:
The general approach how to match parameters in the query and parameters in the method call.
either we iterate the method parameters (and basically hope the matching (by name or index) parameters exist in the query). This is implemented in the ParameterBinder.bind(Query
if we have the StringQuery we can ask it for the parameters and find matching method parameters (or other sources i.e. SpEL expressions).
Decide which query parameter should be filled from which source
use whatever method parameter is available and assume a matching query parameter exists
find parameter by index or name
use a SpEL expression
This choice is implemented in the ParameterBinder.bind(JpaParameter parameter, Object value, Integer position) and in QueryParameterSetterStrategies;
Decide how to set the parameter value in the query. This is encoded in the various QueryParameterSetters
use index or name or ParameterExpression based access
Kevin Peters opened DATAJPA-1140 and commented
Due to a binding issue it's not possible to mix a SpEL
@Param
and a String@Param
on a Repository finder annotated with@Query
if not all incoming parameters are used in SpEL syntax.Example which fails:
This exception is thrown.
Using String parameter as SpEL works:
The order of the params (SpEL first / SpEL last) does not matter
Affects: 2.0 M4 (Kay)
Issue Links:
@Query
method with mixed SpEL and simple binding failed("is duplicated by")
("is duplicated by")
Referenced from: pull request #206, and commits d15139f, c76584f, f2ede44, 8dbbe55, f97928e, b9a57f8, 7a21c8f, 6bedbab, 0529f69, d7c3d01, 3568c51, 3fd8ef2, 3925be3, 3620ab2, 37aabff
The text was updated successfully, but these errors were encountered: