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

#3109
  • Loading branch information
MelleD authored Mar 27, 2024
1 parent da5b440 commit de86680
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
package com.querydsl.jpa.impl;

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.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
Expand Down Expand Up @@ -46,9 +49,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 @@ -148,8 +151,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 @@ -348,7 +351,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 de86680

Please sign in to comment.