如何使用弃用警告修复Hibernate查询?

有人知道如何避免以下代码的下一个警告吗?

org.hibernate.hql.internal.ast.HqlSqlWalker [HqlSqlWalker.java:929] [DEPRECATION] Encountered positional parameter near line 1, column 56.  Positional parameter are considered deprecated; use named parameters or JPA-style positional parameters instead.

Hibernate: select user0_.ID_USER as ID1_0_, user0_.USERNAME as USERNAME0_, user0_.PASSWORD as PASSWORD0_ from USER user0_ where user0_.USERNAME=?

Hibernate: select authoritie0_.ID_USER as ID1_0_1_, authoritie0_.ID_ROLE as ID2_1_, role1_.ID_ROLE as ID1_2_0_, role1_.NOMBRE as NOMBRE2_0_, role1_.DESCRIPCION as DESCRIPC3_2_0_ from USER_ROLE authoritie0_ inner join ROLE role1_ on authoritie0_.ID_ROLE=role1_.ID_ROLE where authoritie0_.ID_USER=?

Query query = sessionFactory.getCurrentSession().createQuery("from User where username=?");

query.setString(0, username);

List<User> users = query.list();

回答:

如消息所示,请改用命名参数。

List users = sessionFactory.getCurrentSession()

.createQuery( "from User where username = :username" )

.setString( "username", username )

.list();

以上是 如何使用弃用警告修复Hibernate查询? 的全部内容, 来源链接: utcz.com/qa/398467.html

回到顶部