<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic NullPointerException when native query with null result in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/nullpointerexception-when-native-query-with-null-result/m-p/155391#M109734</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi there,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We need to find out the last executed process with a given name so we used this piece of code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-java line-numbers"&gt;&lt;CODE&gt;NativeHistoricProcessInstanceQuery haiq = historyService.createNativeHistoricProcessInstanceQuery();&lt;BR /&gt;HistoricProcessInstance processNative = haiq.sql("SELECT MAX(id_) AS id FROM act_hi_procinst WHERE business_key_ = '"+processName+"'").singleResult(); &lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and then with the max id we will load the whole HistoricProcessInstanceQuery:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-java line-numbers"&gt;&lt;CODE&gt;HistoricProcessInstanceQuery hquery = historyService.createHistoricProcessInstanceQuery();&lt;BR /&gt;return hquery.processInstanceId(processNative.getId()).singleResult();&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is that when the native query of SELECT MAX() has &lt;/SPAN&gt;&lt;STRONG&gt;null&lt;/STRONG&gt;&lt;SPAN&gt; result because there is no process executed with the given "processName" name, then throws&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color:#FF0000;"&gt;&lt;BR /&gt;java.lang.NullPointerException&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;at org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntityManager.findHistoricProcessInstanceCountByNativeQuery(HistoricProcessInstanceEntityManager.java:99)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and does not returns &lt;/SPAN&gt;&lt;STRONG&gt;null&lt;/STRONG&gt;&lt;SPAN&gt; as we would expect.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have a workaround for this problem other than catching the NullPointerException in a try-catch block?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 Oct 2013 15:05:59 GMT</pubDate>
    <dc:creator>lotzy</dc:creator>
    <dc:date>2013-10-01T15:05:59Z</dc:date>
    <item>
      <title>NullPointerException when native query with null result</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/nullpointerexception-when-native-query-with-null-result/m-p/155391#M109734</link>
      <description>Hi there,We need to find out the last executed process with a given name so we used this piece of code:NativeHistoricProcessInstanceQuery haiq = historyService.createNativeHistoricProcessInstanceQuery();HistoricProcessInstance processNative = haiq.sql("SELECT MAX(id_) AS id FROM act_hi_procinst WHER</description>
      <pubDate>Tue, 01 Oct 2013 15:05:59 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/nullpointerexception-when-native-query-with-null-result/m-p/155391#M109734</guid>
      <dc:creator>lotzy</dc:creator>
      <dc:date>2013-10-01T15:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: NullPointerException when native query with null result</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/nullpointerexception-when-native-query-with-null-result/m-p/155392#M109735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have implemented small jUnit test (&lt;/SPAN&gt;&lt;A href="https://github.com/martin-grofcik/Activiti/commit/b311ba6c8729633c17df1d33ad42288b9ac386ee" rel="nofollow noopener noreferrer"&gt;https://github.com/martin-grofcik/Activiti/commit/b311ba6c8729633c17df1d33ad42288b9ac386ee&lt;/A&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;code&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Deployment(resources = {"org/activiti/engine/test/history/oneTaskProcess.bpmn20.xml"})&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void testNativeHistoricProcessInstanceQuery() {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NativeHistoricProcessInstanceQuery haiq = historyService.createNativeHistoricProcessInstanceQuery();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HistoricProcessInstance processNative = haiq.sql("SELECT MAX(id_) AS id FROM act_hi_procinst WHERE business_key_ = 'DOES_NOT_EXIST'").singleResult();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; assertEquals(null, processNative);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;/code&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It passes. May be I did something wrong. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Question&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Could you create jUnit test for it?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Idea&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you query DB to get rows count before SELECT MAX(id_) ? (I know it is overhead.)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Oct 2013 04:44:43 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/nullpointerexception-when-native-query-with-null-result/m-p/155392#M109735</guid>
      <dc:creator>martin_grofcik</dc:creator>
      <dc:date>2013-10-02T04:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: NullPointerException when native query with null result</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/nullpointerexception-when-native-query-with-null-result/m-p/155393#M109736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks a lot Martin, for your fast response. We ran the JUnit test with our Activiti version 5.12.1 and we got the same NullPointerException, then we upgraded to version 5.13 and we did NOT encounter the error. So this bug is resolved in the latest version of Activiti. Case closed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Oct 2013 09:29:57 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/nullpointerexception-when-native-query-with-null-result/m-p/155393#M109736</guid>
      <dc:creator>lotzy</dc:creator>
      <dc:date>2013-10-03T09:29:57Z</dc:date>
    </item>
  </channel>
</rss>

