JPQL. JPA Query. How to get size of named parameter collection

Viewed 243

I'm trying to define custom method in repository interface

public interface RequestRepository extends JpaRepository<Request, Long> {

@Query("SELECT r FROM Request r " +
        "LEFT JOIN FETCH r.pathParams pp " +
        "WHERE r.responseCode = :code " + 
        "AND r.requestMethod = :method " +
        "AND r.requestPath = :path " +
        "AND r.requestBody = :body " +
        "AND r.apiDetails = :apidetails " +
        "AND (pp IN :pathparams OR r.pathParams IS EMPTY) " + 
        "AND SIZE(r.pathParams) = :pathparamssize " 
        )
Optional<Request> findByDetails(
        @Param("code") String code, 
        @Param("method") RequestMethod method,
        @Param("path") String path,
        @Param("body") RequestBody body,
        @Param("apidetails") ApiDetails apidetails,
        @Param("pathparams") Set<PathParam> pathparams,
        @Param("pathparamssize") Integer pathparamssize
        );

}

It works, but I believe it can be done in better way

As you can see I declared redundant parameter "pathparamssize" (IMO)

I tried to do that like "AND SIZE(r.pathParams) = SIZE(:pathparams) " but it doesn't want to work with "SIZE(:pathparams)"

can you please advise something?

many thanks in advance

0 Answers
Related