How to write a query in hibernate for count(*)

前端 未结 2 790
感动是毒
感动是毒 2021-02-03 21:50

I want to execute the below query in Hibernate?

select count(*) from login where emailid=\'something\' and password=\'something\'

相关标签:
2条回答
  • 2021-02-03 22:36

    Suppose your login table is mapped by a LoginClass class, with emailid and password instance variables. Then you'll execute something like:

    Query query = session.createQuery(
            "select count(*) from LoginClass login where login.emailid=:email and login.password=:password");
    query.setString("email", "something");
    query.setString("password", "password");
    Long count = (Long)query.uniqueResult();
    

    It should return in count the result you're looking for. You just have to adapt the name to your class and your parameter names.

    0 讨论(0)
  • 2021-02-03 22:47

    other solution may be createSQLQuery("SQL STATEMENT") if you Compelled to good luck

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