JPA本机查询中的位置参数存在问题 [英] Problem with positional parameters in JPA native query
本文介绍了JPA本机查询中的位置参数存在问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图这样做:
I'm trying to do:
String sql = "SELECT email FROM users WHERE (type like 'B') AND (username like '?1')";
List results = em.createNativeQuery(sql).setParameter(1, username).getResultList();
但是我得到IllegalArgumentException,它告诉我该参数超出范围。我在做什么错了?
But I get IllegalArgumentException that tells me that the parameter is out of bounds. What am I doing wrong?
推荐答案
这些参数没有引号。试试这个:
There shoudn't be quotes around the parameters. Try this instead:
String sql = "SELECT email FROM users WHERE (type like 'B') AND (username like ?1)";
您可能还想仔细检查一下,您确实是指类型,如' B'
,因为这可能不符合你的想法。
You might also want to double-check that you really mean type like 'B'
as this probably doesn't do what you think it does.
这篇关于JPA本机查询中的位置参数存在问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文