[英]hibernate query with named parameter giving no result
I am facing problem when using hibernate named parameters in spring MVC 我在Spring MVC中使用休眠命名参数时遇到问题
Session session = sessionFactory.openSession();
Query q = session.createQuery("from Users u where u.username = :name and u.password = :pass");
q.setParameter("name", username);
q.setParameter("pass", password);
Users user = (Users) q.uniqueResult();
The output when using log4j is and printing user 使用log4j时的输出是和打印用户
2017-01-20 22:34:17 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - "test"
2017-01-20 22:34:17 TRACE BasicBinder:83 - binding parameter [2] as [VARCHAR] - "test"
user = null
And when I use query like: 当我使用类似查询:
"from Users u where u.username = 'test' and u.password = 'test'"
I get the user values. 我得到了用户价值。
What am I doing wrong here? 我在这里做错了什么?
Judging by the hibernate log for basic-binder
. 从休眠日志判断
basic-binder
。 Your variable username
and password
contain two double quotes(at the start and end). 您的变量
username
和password
包含两个双引号(在开头和结尾)。
Look at the variables in a debugger or try hardcoding the values in the setParameter
methods. 查看调试器中的变量,或尝试对
setParameter
方法中的值进行硬编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.