Reputation: 31
I'm trying to build and execute a dynamic query that looks like this:
String query = "SELECT e FROM Employee e WHERE (1=1) AND (UPPER(e.lastName) LIKE :lastName)";
final TypedQuery<Employee> dbQuery = entityManager.createQuery(query, Employee.class);
dbQuery.setParameter("lastName", "%" + value.toString().toUpperCase() + "%"));
But it fails with this error:
org.hibernate.QueryException: Not all named parameters have been set: [lastName]
Most interesting is that in debug mod i can see that dbQuery has a bind for "lastName" parameter and contains the specified value inside its "parameterRegistrations" field. So i have no idea.
Alternative with using positional parameters like
dbQuery.setParameter(1, "%" + value.toString().toUpperCase() + "%"));
is not my case, so pls lets do not discuss it.
This question is similar to mine but it's still unanswered.
Upvotes: 0
Views: 178
Reputation: 31
Sorry guys! It was my inattention. A super strange and legacy code was there, which was creating a new instance of TypedQuery much later based on my query, but without parameters. I didn't expect it. That was the reason.
Upvotes: 1