Wednesday, 21 August 2013

getSingleResult() in JPA thorws exceptions

getSingleResult() in JPA thorws exceptions

I was querying using JPA, and when I used
query.getSingleResult();
It was throwing exceptions. I am well aware that if more than one record
matching the parameters the method throws an exception, but in my case the
parameter was a primary key , so that implies the result would have been
unique. But instead of the above method , when i used
query.getResultList();
I had no such issues. I am confused. Similarly when I used the method
query.setMaxResults(some value);
and then tried to get the result list, My program throws hell of errors..!
more details regarding this is in my previous question Error while
querying in JPA.

No comments:

Post a Comment