1

I am new to Hibernate and trying to implement simple native query but I am always getting 0 rows. If the same query I am directly running in db then I can see the records.

    Query query = (Query) entityManager.createNativeQuery("SELECT * FROM USER_PROFILE where ROLE_ID=:roleId "
                + "and USER_EMAIL =:userEmail and USER_PWD=:password");
        query.setParameter("roleId",rolId );
        query.setParameter("userEmail", username.toLowerCase());
        query.setParameter("password", encryptedPwd);

       userInfos = query.getResultList();

But always userInfos list is empty. Can someone suggest what is going wrong.

mhasan
  • 3,703
  • 1
  • 18
  • 37
user3541321
  • 165
  • 5
  • 19
  • wrong database? – Scary Wombat Oct 03 '16 at 07:30
  • Did you tried without the 'encryptedPwd' argument? You store the encrypted pass in the db? Enrcrypting use something like md5 and maybe is truncated ? Give more details please. – DanieleO Oct 03 '16 at 07:31
  • what values are contained in your attributes rolId, username & encryptedPwd for which you dont get result? plz put them in your answer as well – mhasan Oct 03 '16 at 07:32
  • 2
    If you change your query to something without any parameters e.g. `"SELECT * FROM USER_PROFILE"` do you get any results? – pleft Oct 03 '16 at 07:32
  • Previously I was using Hql like Query query = (Query) entityManager .createQuery("from UserInfo where userEmail=:userEmail and password=:password "); and with the same argument it was working fine. – user3541321 Oct 03 '16 at 07:39
  • so basically the addition of the roleId parameter makes it so you get no results. – Gimby Oct 03 '16 at 08:01
  • did you run your script in client directly? – CompEng Oct 03 '16 at 08:22

1 Answers1

0

Thank you everyone for your suggestion. I did a mistake here and password was getting encrypted twice. :( Fixed now.

user3541321
  • 165
  • 5
  • 19