如何在HQL查询中传递参数 [英] How to pass parameter in HQL query
本文介绍了如何在HQL查询中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的HQL查询下面找到
find below my HQL query
Query query = session.createQuery("select u from UserLog u where u.userLogSerialno = " + "(select max(uu.userLogSerialno) from UserLog uu where uu.userId = u.userId)");
此查询工作正常,但在此情况下,我想传递userId的值,但我不知道如何执行此操作. 请帮助..! 在此先感谢.. !!
This query is working fine but in this, I want to pass the value of userId but I am not able to figure out how to do this. Kindly Help..!! Thanks in Advance..!!
推荐答案
我很容易将参数添加到HQL
I is very simple to add parameter to an HQL
Query query = session.createQuery("select u from UserLog u where u.userLogSerialno = " + "(select max(uu.userLogSerialno) from UserLog uu where uu.userId = :userId)").setParameter("userId", 15);
这里我有15个硬编码,您可以简单地使用变量代替它
here i have hard coded 15 you can simply use variable instead of it
这篇关于如何在HQL查询中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文