How to pass parameter in HQL query

前端 未结 2 493
Happy的楠姐
Happy的楠姐 2021-01-19 07:00

find below my HQL query

 Query query = session.createQuery(\"select u from UserLog u where u.userLogSerialno = \" + \"(select max(uu.userLogSerialno) from Us         


        
相关标签:
2条回答
  • 2021-01-19 07:11

    Simple example:

    Integer id = 1;
    Query query = session.createQuery("from Employee e where e.idEmployee=:id");
    query.setParameter("id", id);
    
    0 讨论(0)
  • 2021-01-19 07:30

    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

    0 讨论(0)
提交回复
热议问题