Skip to content

Commit

Permalink
Remove join fetches from entity find query since it causes issues wit…
Browse files Browse the repository at this point in the history
…h multiple associations and it is not needed for query
  • Loading branch information
agrancaric committed Jul 1, 2024
1 parent f91694f commit 18ae793
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public final class RegistryQueryConstants {

public static final String FIND_QUERY_SEPARATOR = " and ";

public static final String FIND_QUERY_JOIN_FETCH = " left join fetch " + ENTITY_ALIAS + ".%s ";

private RegistryQueryConstants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.croz.nrich.registry.api.core.service.RegistryEntityFinderService;
import net.croz.nrich.registry.core.constants.RegistryCoreConstants;
import net.croz.nrich.registry.core.constants.RegistryQueryConstants;
import net.croz.nrich.registry.core.support.ManagedTypeWrapper;
import org.modelmapper.ModelMapper;
Expand Down Expand Up @@ -49,13 +48,8 @@ public class EntityManagerRegistryEntityFinderService implements RegistryEntityF
public <T> T findEntityInstance(Class<T> type, Object id) {
QueryCondition queryCondition = queryWherePartWithParameterMap(type, id, true);

String joinFetchQueryPart = classNameManagedTypeWrapperMap.get(type.getName()).getSingularAssociationList().stream()
.map(attribute -> String.format(RegistryQueryConstants.FIND_QUERY_JOIN_FETCH, attribute.getPath()))
.collect(Collectors.joining(RegistryCoreConstants.SPACE));

String entityWithAlias = String.format(RegistryQueryConstants.PROPERTY_SPACE_FORMAT, type.getName(), RegistryQueryConstants.ENTITY_ALIAS);
String querySelectPart = String.format(RegistryQueryConstants.PROPERTY_SPACE_FORMAT, entityWithAlias, joinFetchQueryPart.trim());
String fullQuery = String.format(RegistryQueryConstants.FIND_QUERY, querySelectPart, queryCondition.wherePart);
String fullQuery = String.format(RegistryQueryConstants.FIND_QUERY, entityWithAlias, queryCondition.wherePart);

@SuppressWarnings("unchecked")
TypedQuery<T> query = (TypedQuery<T>) entityManager.createQuery(fullQuery);
Expand Down

0 comments on commit 18ae793

Please sign in to comment.