[英]TypedQuery error "Not all named parameters have been set" when they had. JPA / Hibernate
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.最有趣的是,在调试模式中,我可以看到 dbQuery 绑定了“lastName”参数,并在其“parameterRegistrations”字段中包含指定值。 So i have no idea.
所以我不知道。
Alternative with using positional parameters like dbQuery.setParameter(1, "%" + value.toString().toUpperCase() + "%"));
替代使用位置参数,如
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.这个问题与我的类似,但仍然没有答案。
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.
这是我的疏忽,那里有一个超级奇怪的遗留代码,它在很久以后根据我的查询创建了一个新的 TypedQuery 实例。 but without parameters.
但没有参数。 I didn't expect it.
我没想到。 That was the reason.
这就是原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.