From a8304da733d5af2ce8b9466144f00a1fd1cdd3b5 Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Fri, 30 Jun 2017 16:56:13 +0200 Subject: [PATCH] Fixed 'distinct' container queries for Oracle; TODO: sql server --- .../midpoint/repo/sql/query2/QueryInterpreter2.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query2/QueryInterpreter2.java b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query2/QueryInterpreter2.java index ed9a691c731..03235ca98f0 100644 --- a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query2/QueryInterpreter2.java +++ b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query2/QueryInterpreter2.java @@ -47,6 +47,7 @@ import com.evolveum.midpoint.util.logging.TraceManager; import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType; import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationWorkItemType; +import org.apache.commons.lang3.StringUtils; import org.hibernate.Session; import org.jetbrains.annotations.NotNull; @@ -146,8 +147,11 @@ u.oid in (select distinct u.oid from RUser u where ...) wrapperQuery.setResultTransformer(resultStyle.getResultTransformer()); wrapperQuery.addProjectionElementsFor(resultStyle.getIdentifiers(wrappedRootAlias)); wrapperQuery.addProjectionElementsFor(resultStyle.getContentAttributes(wrappedRootAlias)); - wrapperQuery.getConditions().add( - wrapperQuery.createIn(wrapperQuery.getPrimaryEntityAlias() + ".oid", subqueryText)); + List inVariablesList = resultStyle.getIdentifiers(wrapperQuery.getPrimaryEntityAlias()); + String inVariablesString = inVariablesList.size() != 1 + ? "(" + StringUtils.join(inVariablesList, ", ") + ")" + : inVariablesList.get(0); + wrapperQuery.getConditions().add(wrapperQuery.createIn(inVariablesString, subqueryText)); wrapperQuery.addParametersFrom(hibernateQuery.getParameters()); return wrapperQuery; } else {