首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

org.hibernate.QueryParameterException: could not locate named.

2012-06-27 
org.hibernate.QueryParameterException: could not locate named...org.hibernate.QueryParameterExcepti

org.hibernate.QueryParameterException: could not locate named...

org.hibernate.QueryParameterException: could not locate named...

其实之前也遇到过这样的问题:

我遇到的是空格:HIbernate查询语句的问题。

例如:String hql = "select m.card_no,cu.name,m.enter_date,m.member_id from member as m ,car as ca,customer as cu ";
String where = " where m.member_id=ca.member_id and m.member_id=cu.member_id";
if(operatorId !=null)
where += " and m.operator_id =:operatorId";

Session session=this.getSession();
try {

Query q= session.createSQLQuery(hql.concat(where).concat(" order by m.card_no desc"));
注意了order by m.card_no desc 语句前的空格,如果没有加空格的话

控制台回报:org.hibernate.QueryParameterException: could not locate named Parameter[operatorId]这样的错误,其实我仔细分析我这里发现是查询语句有问题,我这里是执行了createSQLQuery 如果是createQuery没有加空格也会有这样的错误。在网上搜索了一番,也有别人的遇到这种情况,但是都是细节问题,有的String hql="from Customer c where c.customerStatus= customerStatus"; 这里“= customerStatus”少了“:”应为“= :customerStatus”,还有的干脆没有设置参数 setParamete等等。往往这样的错误很难发现。往往注意细节,对于编程很重要。

?

热点排行