我有一個由活動用戶的布爾值組成的用戶表如下表引起:org.hibernate.QueryException:並非所有命名參數已設置:[isActive] [來自用戶,其中isActive =:isActive]
id | name | active
1 | john | false
2 | bob | true
3 | jeff | true
在上述結構中,我想檢索isActive等於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)
請在那裏我得到它錯在我嘗試。我已經研究過,但並非針對所面臨的問題。
方法setPrameter(字符串,布爾)是未定義的類型查詢 – Francis
看到的setParameter(...)@Francis – developerbhuwan
這個解決我的問題 – Francis