2016-08-19 09:44:27 [org.hibernate.hql.internal.ast.HqlSqlWalker]-[WARN] [DEPRECATION] Encountered positional parameter near line 1, column 77 in HQL: [select o from com.lqy.spring.iwx.bean.User o where 1=1 and o.userName like ? and o.deleteType = ?1 order by o.createTime desc]. Positional parameter are considered deprecated; use named parameters or JPA-style positional parameters instead.
Positional parameter are considered deprecated; use named parameters or JPA-style positional parameters instead.
意思就是说:?号占位参数在考虑作废,请使用命名参数或者Jpa样式的占位参数代替。
二、解决方案:
方法一:改成命名参数的方式:
//命名参数的方式 String hql = "select t from t_usert where t.name=:name"; Query query = getSession().createQuery(hql); query.setParameter("name", "李四");
方法二:改成JPA占位符的方式(?号后面有带数字):
//JPA占位符方式 String hql = "select t from t_user t where t.name=?0"; Query query = getSession().createQuery(hql); query.setParameter(0, "李四");
StringBuffer whereSql = new StringBuffer("");List params = new ArrayList();LinkedHashMap orderBy = new LinkedHashMap (); int paramPosition = 1; if(!StrUtils.isBlank(userName)){ whereSql.append(" and o.userName like ?").append(paramPosition++); params.add("%"+userName+"%");}if(!StrUtils.isBlank(loginName)){ whereSql.append(" and o.loginName = ?").append(paramPosition++); params.add(loginName);}
StringBuffer whereSql = new StringBuffer("");LinkedHashMap orderBy = new LinkedHashMap ();Map paramsMap = new HashMap (); if(!StrUtils.isBlank(userName)){ whereSql.append(" and o.userName like :userName"); paramsMap.put("userName", "%"+userName+"%");}if(!StrUtils.isBlank(loginName)){ whereSql.append(" and o.loginName = :loginName"); paramsMap.put("loginName", loginName);}