简体   繁体   English

TypedQuery 错误“未设置所有命名参数”。 JPA / Hibernate

[英]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.

相关问题 HIbernate:尚未设置所有“命名”参数 - HIbernate: Not all Named parameters have been set org.hibernate.QueryException:并非所有命名参数都已设置:[] - org.hibernate.QueryException: Not all named parameters have been set:[] 并非所有命名参数都在createSQLQuery中设置了hibernate - not all named parameters have been set hibernate in createSQLQuery 如何解决“ org.hibernate.QueryException:尚未设置所有命名参数”的错误? - How to solve “org.hibernate.QueryException: Not all named parameters have been set” error? Spring SpEL JPA @Query-使用数字列获取“ QueryException:尚未设置所有命名参数” - Spring SpEL JPA @Query - getting “QueryException: Not all named parameters have been set” with numeric column 原因:org.hibernate.QueryException:尚未设置所有命名参数:[isActive] [来自用户,其中isActive =:isActive] - Caused by: org.hibernate.QueryException: Not all named parameters have been set: [isActive] [from User where isActive = :isActive] 并非所有命名参数都已在特定条件下设置 - Not all named parameters have been set in specific conditions QueryException:尚未设置所有命名参数:[已停用] - QueryException: Not all named parameters have been set: [Deactivated] org.hibernate.QueryException:并非所有参数都已设置 - org.hibernate.QueryException: not all parameters have been set 带有命名参数的本机查询失败,并且“未设置所有已命名的参数” - Native query with named parameter fails with “Not all named parameters have been set”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM