本文介绍了由以下原因引起:org.hibernate.QueryException:尚未设置所有命名的参数:[isActive] [来自用户,其中isActive =:isActive]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个由活动用户的布尔值组成的用户表,如下表所示
I have a table of users made up of a boolean value of active users as shown in the following table
id | name | active
1 | john | false
2 | bob | true
3 | jeff | true
在上述结构中,我要检索isActive等于true的用户列表.
On the above structure, I want to retrieve the list of users where isActive is equal to true.
这是我的hql查询
public List getByIsActive(boolean isActive) {
return getSession().createQuery(
"from User where isActive = :isActive").list();
}
我正在这样检索
@ResponseBody
@RequestMapping(value = "/get-all-activeusers", method = RequestMethod.GET)
public List<User> getAllActiveUsers() {
try {
boolean isActive = true;
return _userDao.getByIsActive(isActive);
} catch (Exception e) {
logger.error("Exception in fetching active users: ", e.getStackTrace());
e.printStackTrace();
}
return null;
}
我收到此错误
Caused by: org.hibernate.QueryException: Not all named parameters have been set: [isActive] [from User where isActive = :isActive]
at org.hibernate.internal.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:401)
at org.hibernate.internal.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:385)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:99)
at com.models.UserDao.getByIsActive(UserDao.java:64)
请尝试将其弄错的地方.我已经研究过了,但它并不是针对所面临的问题量身定制的.
Please where I getting it wrong in my attempt. I have researched but it is not tailored to the problem am facing.
推荐答案
您忘记为命名参数设置参数:更改dao方法,例如:
You forget to set parameter for named parameters : change dao method like:
public List getByIsActive(boolean isActive) {
return getSession().createQuery(
"from User where isActive = :isActive").setParameter("isActive", isActive)
.list();
}
这篇关于由以下原因引起:org.hibernate.QueryException:尚未设置所有命名的参数:[isActive] [来自用户,其中isActive =:isActive]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!