<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: `TaskQuery.and(TaskQuery)` and `CaseQuery.and(CaseQuery)` doesn't work with `additionalProperty()`.</title><link>https://answers.axonivy.com/questions/1337/taskquery-and-taskquery-and-casequery-and-casequery-doesn-t-work-with-additionalproperty</link><description>&lt;p&gt;On our project, we extensively uses the API &lt;code&gt;TaskQuery&lt;/code&gt; and &lt;code&gt;CaseQuery&lt;/code&gt; in order to find &lt;code&gt;ITask&lt;/code&gt; and &lt;code&gt;ICase&lt;/code&gt; respectively. We also make use of the &lt;code&gt;additionalProperty&lt;/code&gt; of both &lt;code&gt;ITask&lt;/code&gt; and &lt;code&gt;ICase&lt;/code&gt; in order to store custom fields.&lt;/p&gt;
&lt;p&gt;However, we later found out that the method &lt;code&gt;and(TaskQuery&lt;/code&gt; and &lt;code&gt;or(TaskQuery)&lt;/code&gt; doesn't work with the criteria &lt;code&gt;additionalProperty&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Consider the below snippet of code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public List&amp;lt;ITask&amp;gt; findTask() {
    Ivy.wf().getTaskQueryExecutor()
            .getResults(TaskQuery.create().where()
                    .state().isEqual(SUSPENDED)
                    .and(hasCustomField()));
}

private static TaskQuery hasCustomField() {
    return TaskQuery.create().where().additionalProperty("custom").isLike("customized_value");
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Runing the code will result as an exception:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;java.sql.SQLException: Column not found: ADDITIONALPROPERTYFORTASK.NAME in statement [SELECT IWA_TASKQUERY.TASKID ....... FROM IWA_TaskQuery WHERE (IWA_TASKQUERY.APPLICATIONID = ? AND (IWA_TASKQUERY."STATE" = ? AND ((ADDITIONALPROPERTYFORTASK.NAME = ? OR ADDITIONALPROPERTYFORTASK.NAME IS NULL) AND ADDITIONALPROPERTYFORTASK."VALUE" LIKE ?))) ORDER BY IWA_TASKQUERY.TASKID ASC]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;While this works:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public List&amp;lt;ITask&amp;gt; findTask() {
    Ivy.wf().getTaskQueryExecutor()
            .getResults(TaskQuery.create().where()
                    .state().isEqual(SUSPENDED)
                    .and().additionalProperty("custom").isLike("customized_value");
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Please note that only the criterion &lt;code&gt;additionalPropety()&lt;/code&gt; has this problem, the other criteria don't.&lt;/p&gt;
&lt;p&gt;Digging a little deeper, I found that the queries produced are different:&lt;/p&gt;
&lt;p&gt;The former (the problematic one) produces:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SELECT * FROM IWA_Task WHERE
 (Column(IWA_TaskQuery.State) = 4 &amp;amp;amp;&amp;amp;amp;
 ((Column(AdditionalPropertyForTask.Name) = custom || Column(AdditionalPropertyForTask.Name) IS NULL)
    &amp;amp;amp;&amp;amp;amp; Column(AdditionalPropertyForTask.Value) LIKE customized_value))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;...whereas the latter produces (correctly):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SELECT *  FROM IWA_Task 
LEFT JOIN IWA_TaskAdditionalProperty ON Column(IWA_TaskQuery.TaskId) = Column(IWA_TaskAdditionalProperty.TaskId)
LEFT JOIN IWA_AdditionalProperty ON Column(IWA_TaskAdditionalProperty.AdditionalPropertyId) = Column(IWA_AdditionalProperty.AdditionalPropertyId)
WHERE (Column(IWA_TaskQuery.State) = 4 &amp;amp;&amp;amp; (Column(AdditionalPropertyForTask.Name) = custom || Column(AdditionalPropertyForTask.Name) IS NULL) &amp;amp;&amp;amp; Column(AdditionalPropertyForTask.Value) LIKE customized_value)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This problem occurs both on &lt;code&gt;TaskQuery&lt;/code&gt; and &lt;code&gt;CaseQuery&lt;/code&gt; and on Axon.ivy 5.1.x (&lt;code&gt;additionalProperty()&lt;/code&gt; has been introduced since 5.1.x).&lt;/p&gt;
&lt;p&gt;I think this is probrably a bug in Axon.ivy query API. While there is a work-around (don't use &lt;code&gt;and(TaskQuery&lt;/code&gt; with &lt;code&gt;additionalProperty()&lt;/code&gt;), I think it is not good to have inconsistency in the API. I hope this would be fixed soon.&lt;/p&gt;
&lt;p&gt;I have created a demo project which can reproduce the problem on Axon.ivy. Download it at &lt;a href="https://app.box.com/s/9wxc8iqqrfmqotljiutqdwlvvoem55dh"&gt;box.net&lt;/a&gt;.&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1337/taskquery-and-taskquery-and-casequery-and-casequery-doesn-t-work-with-additionalproperty" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 01 Jul 2015 16:09:44 -0400</lastBuildDate><item><title>Answer by Flavio Sadeghi</title><link>https://answers.axonivy.com/questions/1337/taskquery-and-taskquery-and-casequery-and-casequery-doesn-t-work-with-additionalproperty/1389</link><description>&lt;p&gt;Thanks for reporting and the created demo project.&lt;/p&gt;
&lt;p&gt;I have just analysed and fixed the API for Axon.ivy 5.1. The next Hotfix is 5.1.6 and will be available on our &lt;a href="http://developer.axonivy.com/download/"&gt;download page&lt;/a&gt; till the end of next week. &lt;/p&gt;
&lt;p&gt;Fore more info or notifications see Issue&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#25579: additionalProperty() does not work with TasQuery or CaseQuery when using .or(..), .and(..) or .not(..)
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Flavio Sadeghi</dc:creator><pubDate>Wed, 01 Jul 2015 16:09:44 -0400</pubDate><guid>https://answers.axonivy.com/questions/1337/taskquery-and-taskquery-and-casequery-and-casequery-doesn-t-work-with-additionalproperty/1389</guid></item></channel></rss>