tkaczmarzyk / specification-arg-resolver

An alternative API for filtering data with Spring MVC & Spring Data JPA
Apache License 2.0
658 stars 150 forks source link

Specification adds duplicate join when query has been built manually with existing join (Spring Boot 3.x) #256

Open janar-rahumeel opened 1 year ago

janar-rahumeel commented 1 year ago

Specification has annotation @Join(path = "googleSearchResults", alias = "gsr"), and @Spec(params = "googleSearchResultSourceQuality", path = "gsr.sourceQuality", spec = Equal.class)}) when I build my query manually that contains already this join

Join<GoogleSearch, GoogleSearchResult> googleSearchResults = googleSearch.join("googleSearchResults", JoinType.LEFT);

and calling

Predicate wherePredicate = specification.toPredicate(googleSearch, criteriaQuery, criteriaBuilder);

provider creates a duplicate join

select
        distinct g1_0.id c0,
        g2_0.name c1,
        g1_0.QUERY c2,
        count(g3_0.ID) c3 
    from
        GOOGLE_SEARCH g1_0 
    join
        GOOGLE_LOCATION g2_0 
            on g2_0.id=g1_0.GOOGLE_LOCATION_ID 
    left join
        GOOGLE_SEARCH_RESULT g3_0 
            on g1_0.id=g3_0.GOOGLE_SEARCH_ID 
    left join
        GOOGLE_SEARCH_RESULT g4_0 
            on g1_0.id=g4_0.GOOGLE_SEARCH_ID 
    where
        g1_0.SEARCH_REQUEST_ID=? 
        and g4_0.SOURCE_QUALITY=? 
        and 1=1 
    group by
        c0,
        c1,
        c2 offset ? rows fetch first ? rows only