Property 'fp' not found in Visitor

I wrote a script and wanted to take the Visitor list through FoodPreference, but when running the script could not find “fp”. How can I fix it?

image

image

image

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class VisitorManufacturerRequest {

    @Nullable
    @Schema(description = "Страница", nullable = true)
    private Integer page;

    @Nullable
    @Schema(description = "Размер", nullable = true)
    private Integer size;

    @Nullable
    @Schema(description = "Текст поиск по еде", nullable = true)
    private String searchText;

    @Nullable
    @Schema(description = "Список id по foodPreference", nullable = true)
    private List<UUID> foodPreferenceIds;
}

public VisitorItemPage getVisitorManufacture(VisitorManufacturerRequest request, String mobile) {
        int page = 0;
        int size = 10;
        LogicalCondition filterCondition = new LogicalCondition(LogicalCondition.Type.AND);
        List<Condition> conditionList = new ArrayList<>();

        if (request.getPage() != null) page = request.getPage();
        if (request.getSize() != null) size = request.getSize();

        if (request.getSearchText() != null && !request.getSearchText().isEmpty()) {
            conditionList.add(
                    PropertyCondition.contains("companyName", request.getSearchText()));
        }
        if (request.getFoodPreferenceIds() != null && !request.getFoodPreferenceIds().isEmpty()) {
            conditionList.add(
                    PropertyCondition.inList("fp.id", request.getFoodPreferenceIds()));
        }
        filterCondition.setConditions(conditionList);

        int offset = page * size;
        boolean hasNext = false;

        List<Visitor> visitorList = dataManagerUc.load(Visitor.class)
                .query("select distinct v from Visitor v " +
                        "left join v.dishCards dc " +
                        "left join dc.foodPreferences fp " +
                        "where dc.status = :status " +
                        "and v.userType = :userType " +
                        "order by v.createdDate DESC")
                .parameter("status", FoodPosterStatusEnum.PUBLISHED)
                .parameter("userType", UserTypeEnum.MANUFACTURER)
                .condition(filterCondition)
                .firstResult(offset)
                .maxResults(size)
                .list();

        // проверка на наличие след страницы
        List<Visitor> nextPage = dataManagerUc.load(Visitor.class)
                .query("select distinct v from Visitor v " +
                        "left join v.dishCards dc " +
                        "left join dc.foodPreferences fp " +
                        "where dc.status = :status " +
                        "and v.userType = :userType " +
                        "order by v.createdDate DESC")
                .parameter("status", FoodPosterStatusEnum.PUBLISHED)
                .parameter("userType", UserTypeEnum.MANUFACTURER)
                .condition(filterCondition)
                .firstResult(offset + size)
                .maxResults(size)
                .list();

        if (!nextPage.isEmpty()) {
            hasNext = true;
        }

        return VisitorItemPage.builder()
                .hasNext(hasNext)
                .page(page)
                .size(size)
                .content(
                        visitorList.stream()
                                   .map(VisitorInfo::of)
                                   .collect(Collectors.toList()))
                .build();
    }

С помощью PropertyCondition можно фильтровать только по свойствам извлекаемой сущности, то есть в вашем случае Visitor и ее to-one связей.

Я бы посоветовал просто свести весь ваш код к формированию одного JPQL-запроса передаваемого в query(), и не использовать condition().