Legacy-style query parameters (`?`) are no longer supported; use JPA-style ordinal parameters (e.g., `?1`) instead

<dependency>
	<groupId>org.hibernate</groupId>
	<artifactId>hibernate-core</artifactId>
	<version>5.4.8.Final</version>
</dependency>
  • 错误方式
String hql = "from Teacher t where  t.teacherName = ? and t.teacherPwd = ?";
Query query = session.createQuery(hql);
query.setParameter(0, username);
query.setParameter(1, password);
报错
Legacy-style query parameters (`?`) are no longer supported; use JPA-style ordinal parameters (e.g., `?1`) instead
不再支持遗留样式的查询参数(' ? ');而是使用jpa风格的序数参数(例如,' ?1 ')
  • 解决
String hql = "from Teacher t where  t.teacherName = ?1 and t.teacherPwd = ?2";
Query query = session.createQuery(hql);
query.setParameter(1, username);
query.setParameter(2, password);

https://blog.csdn.net/m0_37922841/article/details/80560127
https://blog.csdn.net/Z_Dalao/article/details/84891149

posted @ 2021-12-09 10:39  MikiKawai  阅读(804)  评论(0编辑  收藏  举报