I am in a somewhat peculiar situation, where I need to generate native SQL queries from TypedQuery
s. I have successfully done that for an unparameterized query, however when I try to reapply the parameters I get the following issue:
I query the ParameterTranslations
for the named parameters via a foreach loop:
for (String name : parameterTranslations.getNamedParameterInformationMap().keySet()) {
Parameter param = typedQuery.getParameter(name);
nativeCountQuery.setParameter(
param.getPosition(),
typedQuery.getParameterValue(name)
);
}
Using the debugger I can establish, that the parameter “param0” that gets assigned to the String name
does in fact exist in the typedQuery
s jpqlQuery.queryParameterBindings.parameterBindingMap
and is also in fact a named parameter of that name.
However I get an IllegalArgumentException
when trying to execute the typedQuery.getParameter(name)
: Caused by: java.lang.IllegalArgumentException: Unable to locate parameter registered with that name [param0]
Am I doing something wrong here, or should I report this as a bug?