序数参数未绑定:@Query批注中的2 [英] Ordinal Parameter Not bound : 2 in @Query annotation

查看:527
本文介绍了序数参数未绑定:@Query批注中的2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试运行此查询时出现以下错误.

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

org.hibernate.QueryException:未绑定序数参数:2,

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

如果我将" WHERE v IN ?2 "更改为" WHERE v IN ?2 OR v IN ?1 ",则它可以工作.我不知道为什么它不起作用.有什么主意吗?

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?

注意:可见性"是升级"类中的Set<String>类型.

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

推荐答案

问题是您在查询中仅声明了一个绑定参数,但实际上在该方法中有两个参数.

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

这是因为在"AND amu.id= '?1' "中,由于包含引号,因此看起来像bind参数的实际上是字符串文字. 如果要将其作为绑定参数进行处理,请删除引号:"AND amu.id= ?1 "

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 "

这篇关于序数参数未绑定:@Query批注中的2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆