<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hello Petr,</p>
<p>I originally thought the following would work; and it would
naturally translate into "IN" clause. </p>
<p><tt><query></tt><tt><br>
</tt><tt>Â <filter></tt><tt><br>
</tt><tt>Â Â Â <equal></tt><tt><br>
</tt><tt>Â Â Â Â Â <path>employeeType</path></tt><tt><br>
</tt><tt>Â Â Â Â Â <value>A</value></tt><tt><br>
</tt><tt>Â Â Â Â Â <value>B</value></tt><tt><br>
</tt><tt>Â Â Â Â Â <value>C</value></tt><tt><br>
</tt><tt>Â Â Â </equal></tt><tt><br>
</tt><tt>Â </filter></tt><tt><br>
</tt><tt></query></tt></p>
<p>But unfortunately it does not, at least not now. Maybe it worked
some time in the past. It is necessary to use <or> for such
comparison.</p>
<p>See also note #2 below <a moz-do-not-send="true"
href="https://wiki.evolveum.com/display/midPoint/Updated+Query+API#UpdatedQueryAPI-Valuefilters">this
table</a>. It would be quite straightforward to implement.<br>
</p>
<hr size="2" width="100%">
<p>But for negative conditions on multivalued items the problem is a
bit deeper: currently we do a join of base entity with all the
entities we need to query (representing e.g. multivalued items)
and then formulate the conditions in the "where" section. Using
this approach it is not possible to specify "give me users that do
<b>not</b> have a particular value of organizationalUnit". <br>
</p>
When driving, just a while before, I thought a bit about this. Maybe
it would not require embedded queries.<br>
<p>This is a standard translation of</p>
<p><tt><query></tt><tt><br>
</tt><tt>Â <filter></tt><tt><br>
</tt><tt>Â Â Â <equal></tt><tt><br>
</tt><tt>Â Â Â Â Â <path>employeeType</path></tt><tt><br>
</tt><tt>Â Â Â Â Â <value>A</value></tt><tt><br>
</tt><tt>Â Â Â </equal></tt><tt><br>
</tt><tt>Â </filter></tt><tt><br>
</tt><tt></query></tt></p>
<p>(I chose employeeType over organizationalUnit just because it's a
plain string, so HQL is a bit simpler.)<br>
</p>
<tt>select</tt><tt><br>
</tt><tt>Â u.oid,</tt><tt><br>
</tt><tt>Â u.fullObject,</tt><tt><br>
 ...<br>
</tt><tt>from</tt><tt><br>
</tt><tt>Â RUser u</tt><tt><br>
</tt><tt>Â Â Â left join u.employeeType e</tt><tt><br>
</tt><tt>where</tt><tt><br>
</tt><tt>Â e = 'A'</tt><tt><br>
</tt><br>
But it could be written also like this:<br>
<br>
<tt>select</tt><tt><br>
</tt><tt>Â u.oid,</tt><tt><br>
</tt><tt>Â u.fullObject,</tt><tt><br>
</tt><tt>Â ...</tt><tt><br>
</tt><tt>from</tt><tt><br>
</tt><tt>Â RUser u</tt><tt><br>
</tt><tt>Â Â Â left join u.employeeType e on e = 'A'</tt><tt><br>
</tt><tt>where</tt><tt><br>
</tt><tt>Â e is not null</tt><tt><br>
</tt><br>
And this condition could be negated quite easily:<br>
<br>
<tt>select</tt><tt><br>
</tt><tt>Â u.oid,</tt><tt><br>
</tt><tt>Â u.fullObject,</tt><tt><br>
</tt><tt>Â ...</tt><tt><br>
</tt><tt>from</tt><tt><br>
</tt><tt>Â RUser u</tt><tt><br>
</tt><tt>Â Â Â left join u.employeeType e on e = 'A'</tt><tt><br>
</tt><tt>where</tt><tt><br>
</tt><tt>Â e is null<br>
</tt><br>
So this would find all users that do not have an employeeType of
'A'!<br>
<br>
We just would need to move the condition from "where ..." to "join
... on ...". This requires some more thinking about possible
consequences, but it would be perhaps doable.<br>
<br>
Do you know of any customer that would like to invest a couple of
man-days (probably not that many days!) into the query interpreter?
:-)<br>
<pre class="moz-signature" cols="72">Pavol Mederly
Software developer
evolveum.com
</pre>
<div class="moz-cite-prefix">On 03.10.2017 8:18, Petr GaÅ¡parÃk - AMI
Praha a.s. wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CABAspd3-TVz+4gQmVLf=cU8p8Q_50MM5HZKuTmTbiKUC9FNerA@mail.gmail.com">
<div dir="ltr">Pavoľ,
<div>is there a way how to use "IN"/"NOT IN" in a filter?</div>
</div>
<div class="gmail_extra"><br clear="all">
<div>
<div class="gmail_signature" data-smartmail="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<p><span
style="font-family:Arial,sans-serif;font-size:10pt">--</span></p>
<p><span
style="font-family:Arial,sans-serif;font-size:10pt">s
pozdravem</span></p>
<table
style="font-family:Verdana,Arial,Helvetica,sans-serif;border-collapse:collapse;padding:0px;margin:0px;border-width:0px!important;border-style:solid!important;width:482px!important">
<tbody>
<tr style="padding:0px;margin:0px;border:0px solid
gray!important">
<td
style="color:rgb(0,0,0);font-family:Arial,sans-serif;font-size:11px;width:160px;vertical-align:bottom;padding:0px;border:0px
solid gray!important">
<p><span
style="font-size:14px;font-weight:bold">Petr
GaÅ¡parÃk</span><br>
solution architect<br>
<br>
gsm: [+420] 603 523 860<br>
e-mail:Â <a
href="mailto:petr.gasparik@ami.cz"
target="_blank" moz-do-not-send="true">petr.gasparik@ami.cz</a></p>
</td>
<td
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10px;border-right-width:1px;border-right-style:solid;border-right-color:rgb(204,204,204);padding:0px;border-top-width:0px!important;border-bottom-width:0px!important;border-left-width:0px!important;border-top-style:solid!important;border-bottom-style:solid!important;border-left-style:solid!important;border-top-color:gray!important;border-bottom-color:gray!important;border-left-color:gray!important">Â Â Â </td>
<td
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10px;padding:0px;border:0px
solid gray!important">Â Â Â </td>
<td
style="color:rgb(0,0,0);font-family:Arial,sans-serif;font-size:11px;vertical-align:bottom;padding:0px;width:123px;border:0px
solid gray!important">
<p>AMI Praha a.s.<br>
PlániÄkova 11<br>
162 00 Praha 6<br>
tel.: [+420] 274 783 239<br>
web:Â <a href="http://www.ami.cz/"
target="_blank" moz-do-not-send="true">www.ami.cz</a></p>
</td>
<td
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10px;border-right-width:1px;border-right-style:solid;border-right-color:rgb(204,204,204);padding:0px;border-top-width:0px!important;border-bottom-width:0px!important;border-left-width:0px!important;border-top-style:solid!important;border-bottom-style:solid!important;border-left-style:solid!important;border-top-color:gray!important;border-bottom-color:gray!important;border-left-color:gray!important">Â Â Â </td>
<td
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10px;padding:0px;border:0px
solid gray!important">Â Â Â </td>
<td
style="color:rgb(0,0,0);font-family:Arial,sans-serif;font-size:11px;margin:8px;border:0px
solid gray!important;width:116px">
<p><img
src="http://www.ami.cz/images/podpis/ami_logo.gif"
alt="AMI Praha a.s." style="border:0px"
moz-do-not-send="true"></p>
</td>
</tr>
<tr style="padding:0px;margin:0px;border:0px solid
gray!important">
<td colspan="7"
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10px;padding:0px;width:480px;border:0px
solid gray!important"><br>
</td>
</tr>
<tr style="padding:0px;margin:0px;border:0px solid
gray!important">
<td colspan="7"
style="color:rgb(128,128,128);font-family:Arial,sans-serif;font-size:11px;padding:0px;border:0px
solid gray!important">Textem tohoto e-mailu
podepisujÃcà neslibuje uzavÅ™Ãt ani neuzavÃrá
za spoleÄnost AMI Praha a.s.<br>
jakoukoliv smlouvu. Každá smlouva, pokud bude
uzavÅ™ena, musà mÃt výhradnÄ› pÃsemnou formu.<br>
<br>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<br>
<div class="gmail_quote">2017-10-03 7:38 GMT+02:00 Pavol Mederly
<span dir="ltr"><<a href="mailto:mederly@evolveum.com"
target="_blank" moz-do-not-send="true">mederly@evolveum.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<p>Hello,</p>
<p>you're right. The <not> clause doesn't work well
(or maybe doesn't work at all) with multivalued items.
The reason is that the translation of such queries to
HQL/SQL is not so straightforward. Some kind of embedded
query or something like that would be needed. You could
create a JIRA for this if you want, but I am not sure
when we'll have some time to implement that.<br>
</p>
<p>And yes, I know that the query interpreter (i.e. the
code that translates midPoint queries to HQL queries)
could be more polite and explain errors in a better
way... again, not enough time for that. :-)<br>
</p>
<p>Best regards,</p>
<pre class="m_4290778675936729897moz-signature" cols="72">Pavol Mederly
Software developer
<a href="http://evolveum.com" target="_blank" moz-do-not-send="true">evolveum.com</a>
</pre>
<div>
<div class="h5">
<div class="m_4290778675936729897moz-cite-prefix">On
02.10.2017 23:17, Alcides Carlos de Moraes Neto
wrote:<br>
</div>
</div>
</div>
<blockquote type="cite">
<div>
<div class="h5">
<div dir="ltr">So, this only happens with
multivalued fields. Single valued fields work just
fine. Is this as intended? </div>
<div class="gmail_extra"><br>
<div class="gmail_quote">2017-09-28 18:51
GMT-03:00 Alcides Carlos de Moraes Neto <span
dir="ltr"><<a
href="mailto:alcides.neto@gmail.com"
target="_blank" moz-do-not-send="true">alcides.neto@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0
0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex">
<div dir="ltr">Hello all,
<div><br>
</div>
<div>I'm trying to make a simple search
query. I want to find all users with an
assignment, that don't have XYZ value for
organizational unit.</div>
<div><br>
</div>
<div>I can do this just fine:</div>
<div>
<div><query></div>
<div>Â Â <filter></div>
<div>Â Â Â Â <and></div>
<div>Â Â Â Â Â Â <ref></div>
<div>Â Â Â Â Â Â Â Â
<path>assignment/targetRef</pa<wbr>th></div>
<div>Â Â Â Â Â Â Â Â <value
oid="7d66fc64-1540-44da-8f3d-c<wbr>565bc917e12"/></div>
<div>Â Â Â Â Â Â </ref></div>
<div>Â Â Â Â Â Â <equal></div>
<div>Â Â Â Â Â Â Â Â
<path>organizationalUnit</path<wbr>></div>
<div>Â Â Â Â Â Â Â Â
<value>XYZ</value></div>
<div>Â Â Â Â Â Â </equal></div>
<div>Â Â Â Â </and></div>
<div>Â Â </filter></div>
<div></query></div>
</div>
<div><br>
</div>
<div>This will fetch users with the
assignment and the value
organizationalUnit XYZ</div>
<div><br>
</div>
<div>If I add the <not>...</div>
<div>
<div><query></div>
<div>Â Â <filter></div>
<div>Â Â Â Â <and></div>
<div>Â Â Â Â Â Â <ref></div>
<div>Â Â Â Â Â Â Â Â
<path>assignment/targetRef</pa<wbr>th></div>
<div>Â Â Â Â Â Â Â Â <value
oid="7d66fc64-1540-44da-8f3d-c<wbr>565bc917e12"/></div>
<div>Â Â Â Â Â Â </ref></div>
<div>Â Â Â Â Â Â <not></div>
<div>Â Â Â Â Â Â Â <equal></div>
<div>Â Â Â Â Â Â Â Â Â
<path>organizationalUnit</path<wbr>></div>
<div>Â Â Â Â Â Â Â Â Â
<value>NQPPPS</value></div>
<div>Â Â Â Â Â Â Â </equal></div>
      </not>
<div>Â Â Â Â </and></div>
<div>Â Â </filter></div>
<div></query></div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>This results in a hibernate error:</div>
<div><span style="color:rgb(51,51,51);font-family:monospace;font-size:11px;white-space:pre-wrap">org.hibernate.HibernateExcepti<wbr>on: SqlNode's text did not reference expected number of columns
at org.hibernate.hql.internal.ast<wbr>.tree.AbstractNullnessCheckNod<wbr>e.extractMutationTexts(Abstrac<wbr>tNullnessCheckNode.java:151)</span><br>
</div>
<div>...</div>
<div><span style="color:rgb(51,51,51);font-family:monospace;font-size:11px;white-space:pre-wrap">at com.evolveum.midpoint.repo.sql<wbr>.query2.hqm.RootHibernateQuery<wbr>.getAsHqlQuery(RootHibernateQu<wbr>ery.java:96)</span><br>
</div>
<div><br>
</div>
<div>Am I doing something wrong? Is it a
bug? I'm using midpoint 3.6</div>
<div>Is there any other way to get what I
want from a query?<br>
</div>
<div><br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset
class="m_4290778675936729897mimeAttachmentHeader"></fieldset>
<br>
</div>
</div>
<span class="">
<pre>______________________________<wbr>_________________
midPoint mailing list
<a class="m_4290778675936729897moz-txt-link-abbreviated" href="mailto:midPoint@lists.evolveum.com" target="_blank" moz-do-not-send="true">midPoint@lists.evolveum.com</a>
<a class="m_4290778675936729897moz-txt-link-freetext" href="http://lists.evolveum.com/mailman/listinfo/midpoint" target="_blank" moz-do-not-send="true">http://lists.evolveum.com/<wbr>mailman/listinfo/midpoint</a>
</pre>
</span></blockquote>
<br>
</div>
<br>
______________________________<wbr>_________________<br>
midPoint mailing list<br>
<a href="mailto:midPoint@lists.evolveum.com"
moz-do-not-send="true">midPoint@lists.evolveum.com</a><br>
<a
href="http://lists.evolveum.com/mailman/listinfo/midpoint"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://lists.evolveum.com/<wbr>mailman/listinfo/midpoint</a><br>
<br>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
midPoint mailing list
<a class="moz-txt-link-abbreviated" href="mailto:midPoint@lists.evolveum.com">midPoint@lists.evolveum.com</a>
<a class="moz-txt-link-freetext" href="http://lists.evolveum.com/mailman/listinfo/midpoint">http://lists.evolveum.com/mailman/listinfo/midpoint</a>
</pre>
</blockquote>
<br>
</body>
</html>