Skip to content

Commit

Permalink
Fix using multi query hints
Browse files Browse the repository at this point in the history
Fix using multi query hints
  • Loading branch information
MelleD authored and velo committed Apr 4, 2024
1 parent 335cd40 commit 6c4cd07
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import com.querydsl.jpa.JPQLTemplates;
import com.querydsl.jpa.QueryHandler;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
Expand All @@ -44,9 +46,9 @@
public abstract class AbstractJPAQuery<T, Q extends AbstractJPAQuery<T, Q>>
extends JPAQueryBase<T, Q> {

private static final Logger logger = Logger.getLogger(JPAQuery.class.getName());
private static final Logger logger = Logger.getLogger(AbstractJPAQuery.class.getName());

protected final Map<String, Object> hints = new LinkedHashMap<>();
protected final Map<String, Collection<Object>> hints = new LinkedHashMap<>();

protected final EntityManager entityManager;

Expand Down Expand Up @@ -146,8 +148,8 @@ protected Query createQuery(@Nullable QueryModifiers modifiers, boolean forCount
query.setFlushMode(flushMode);
}

for (Map.Entry<String, Object> entry : hints.entrySet()) {
query.setHint(entry.getKey(), entry.getValue());
for (Map.Entry<String, Collection<Object>> entry : hints.entrySet()) {
entry.getValue().forEach(value -> query.setHint(entry.getKey(), value));
}

// set transformer, if necessary and possible
Expand Down Expand Up @@ -352,7 +354,8 @@ public Q setFlushMode(FlushModeType flushMode) {

@SuppressWarnings("unchecked")
public Q setHint(String name, Object value) {
hints.put(name, value);
hints.computeIfAbsent(name, key -> new LinkedHashSet<>());
hints.get(name).add(value);
return (Q) this;
}

Expand Down

0 comments on commit 6c4cd07

Please sign in to comment.