setParameter不支持传统的按位置查询方式

setParameter不支持传统的按位置查询方式

		String hql = "from Customer as c where c.cust_id = ?";
List<Customer> list = session.createQuery(hql).setParameter(0, 2l).list();
for (Customer customer : list) {
System.out.println(customer);
}

出现错误

Legacy-style query parameters (`?`) are no longer supported;
use JPA-style ordinal parameters (e.g., `?1`) instead :
from com.hibernate.domain.Customer as c where c.cust_id = ?
[from com.hibernate.domain.Customer as c where c.cust_id = ?]

更改方法

?的后面加个整数的数,然后在使用setParameter的时候使用当时的添加的整数进行绑定

		String hql = "from Customer as c where c.cust_id = ?1";
List<Customer> list = session.createQuery(hql).setParameter(1, 2l).list();
for (Customer customer : list) {
System.out.println(customer);
}
上一篇:scrt中使用alt键


下一篇:K - FatMouse and Cheese