关于Hibernate的占位符问题。

当使用Hibernate占位符时,用?会报一个错误。

Forum other = (Forum) getSession().createQuery(     
                "from Forum f where f.position < ? order by f.position desc ")
                .setParameter(0, forum.getPosition())
                .setFirstResult(0)
                .setMaxResults(1).uniqueResult();

``

`
WARN HqlSqlWalker:1009 - [DEPRECATION] Encountered positional parameter near line 1, column 50 in HQL: [from com.yh.oa.domain.Forum f where f.position > ? order by f.position asc ]. Positional parameter are considered deprecated; use named parameters or JPA-style positional parameters instead.

改进方案:用命名参数方式占位

Forum other = (Forum) getSession().createQuery(
“from Forum f where f.position < :position order by f.position desc “)
.setParameter(“position”, forum.getPosition())
.setFirstResult(0)
.setMaxResults(1).uniqueResult();
“`

你可能感兴趣的:(Hibernate,Parameters,deprecated,Positional)