Skip to content

Commit

Permalink
Merge pull request #213 from croz-ltd/feature_removdJoinFetchFromFind…
Browse files Browse the repository at this point in the history
…Alias

Remove join fetches from entity find query
  • Loading branch information
jzrilic authored Jul 1, 2024
2 parents f91694f + 18ae793 commit ac7e877
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 ac7e877

Please sign in to comment.