Does a query execution always have to return a list ? How do I replace the code below if I am sure it will only return a single object ?
@Override
public List<DocInfo> findAllByDocId(String docId)
{
Query q = getCurrentSession().createQuery("from DocInfo item where item.id = :docId");
q.setString("docId", docId);
List<DocInfo> docInfoList = q.list();
return docInfoList;
}
You can use Query#uniqueResult() with Hibernate if I am not wrong. I think that is what you are looking for. In this case, you have to handle the NonUniqueResultException
in your code if there is more than one row returned from your query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With