Before I posted this question, I already looked this, but I couldn\'t get what I was looking for.
I know that for the query I wrote there may exist only one row or n
When you don't know whether there are any results, use getResultList().
getResultList()
List foundUsers = (List) query.getResultList(); if (foundUsers == null || foundUsers.isEmpty()) { return false; } User foundUser = foundUsers.get(0);