<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Persistence Api - Catching NoResultException</title><link>https://answers.axonivy.com/questions/1049/persistence-api-catching-noresultexception</link><description>&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;How do I catch a NoResultException after calling the getSingleResult() on a custom query, wich often doesn't return any result. Catching the NoResultException still logs an error (&lt;strong&gt;NoResultException: No entity found for query&lt;/strong&gt;) and after that the Info is printed out. Happens both in the designer and on the server.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;catch (NoResultException e) {
    Ivy.log().info("No Result has been found for Debitor '"+number+"'.");
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;haven't tested yet with other Exceptions like NonUniqueResultException.&lt;/p&gt;
&lt;p&gt;Thank you in advance&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1049/persistence-api-catching-noresultexception" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 26 Nov 2014 09:19:53 -0500</lastBuildDate><item><title>Answer by Reto Weiss</title><link>https://answers.axonivy.com/questions/1049/persistence-api-catching-noresultexception/1051</link><description>&lt;p&gt;If you are not sure if there is a single result available or if more than one result is available use the method getResultList() instead of getSingleResult(). Then check if the returning List is empty or contains more than one entry.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Wed, 26 Nov 2014 09:19:53 -0500</pubDate><guid>https://answers.axonivy.com/questions/1049/persistence-api-catching-noresultexception/1051</guid></item></channel></rss>