How to pass parameter in HQL query

别来无恙 提交于 2019-12-02 01:40:58

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

here i have hard coded 15 you can simply use variable instead of it

Simple example:

Integer id = 1;
Query query = session.createQuery("from Employee e where e.idEmployee=:id");
query.setParameter("id", id);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!