25

次のコードの次の警告を回避する方法を知っている人はいますか?

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();
4

3 に答える 3

44

メッセージにあるように、代わりに名前付きパラメーターを使用してください。

List users = sessionFactory.getCurrentSession()
        .createQuery( "from User where username = :username" )
        .setString( "username", username )
        .list();
于 2012-05-25T13:14:10.730 に答える