Ordinal Parameter Not bound : 2 in @Query annotation

陌路散爱 提交于 2019-12-04 06:43:45

问题


I am getting following error when I try to run this query.

org.hibernate.QueryException: Ordinal parameter not bound : 2",

@Query(value = "SELECT amu " +
                   "FROM Upgrade amu " +
                    "INNER JOIN FETCH amu.visibility v " +
                   " WHERE v IN ?2 " +
                    "AND amu.id= '?1' "         
   )
Optional<Upgrade> myFindMethod(final String uid, final String cid);

If I change " WHERE v IN ?2 " with " WHERE v IN ?2 OR v IN ?1 ", then it works. I have no idea why it does not work. Any idea?

Note: Visibility is type of Set<String> in the Upgrade class.


回答1:


The problem is that you have only one bind parameter declared in the query but have actually two parameters in the method.

This is because in "AND amu.id= '?1' " what looks like a bind parameter is actually a string literal due to the enclosing quotes. If you want that to be handled as a bind parameter remove the quotes: "AND amu.id= ?1 "



来源:https://stackoverflow.com/questions/58958908/ordinal-parameter-not-bound-2-in-query-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!