TypedQuery.getParameter fails even though parameter exists

I am in a somewhat peculiar situation, where I need to generate native SQL queries from TypedQuerys. 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);

Using the debugger I can establish, that the parameter “param0” that gets assigned to the String name does in fact exist in the typedQuerys 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?

It’s hard to say without seeing the full code. Please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(hibernate-test-case-templates/JPAUnitTestCase.java at master · hibernate/hibernate-test-case-templates · GitHub) that reproduces the issue.

Hello beikov,

I have added the TestCase to the ticket which you can find here:

[HHH-14451] TypedQuery::getParameter does not work with CriteriaQueries - Hibernate JIRA (atlassian.net)

I would appreciate it if you took a look at it. Thank you for your time.

Thanks, I’ll take a look as soon as I can. I added this issue to my todo list.