From 18ae793f5a5689e11317c829152d38aec516c84b Mon Sep 17 00:00:00 2001 From: agrancaric Date: Mon, 1 Jul 2024 09:53:43 +0200 Subject: [PATCH] Remove join fetches from entity find query since it causes issues with multiple associations and it is not needed for query --- .../registry/core/constants/RegistryQueryConstants.java | 2 -- .../service/EntityManagerRegistryEntityFinderService.java | 8 +------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/nrich-registry/src/main/java/net/croz/nrich/registry/core/constants/RegistryQueryConstants.java b/nrich-registry/src/main/java/net/croz/nrich/registry/core/constants/RegistryQueryConstants.java index 197bf7813..c13fa4a88 100644 --- a/nrich-registry/src/main/java/net/croz/nrich/registry/core/constants/RegistryQueryConstants.java +++ b/nrich-registry/src/main/java/net/croz/nrich/registry/core/constants/RegistryQueryConstants.java @@ -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() { } } diff --git a/nrich-registry/src/main/java/net/croz/nrich/registry/core/service/EntityManagerRegistryEntityFinderService.java b/nrich-registry/src/main/java/net/croz/nrich/registry/core/service/EntityManagerRegistryEntityFinderService.java index eaeec4ca9..44beec3de 100644 --- a/nrich-registry/src/main/java/net/croz/nrich/registry/core/service/EntityManagerRegistryEntityFinderService.java +++ b/nrich-registry/src/main/java/net/croz/nrich/registry/core/service/EntityManagerRegistryEntityFinderService.java @@ -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; @@ -49,13 +48,8 @@ public class EntityManagerRegistryEntityFinderService implements RegistryEntityF public T findEntityInstance(Class 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 query = (TypedQuery) entityManager.createQuery(fullQuery);