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 using java 8, you may take advantage of stream API and simplify code to
return (YourEntityClass) entityManager.createQuery()
....
.getResultList()
.stream().findFirst();
That will give you java.util.Optional
If you prefer null instead, all you need is
...
.getResultList()
.stream().findFirst().orElse(null);