JPA query for select which multiple values in the “IN” clause

前端 未结 1 1240
无人及你
无人及你 2021-01-15 17:49

I want to create a JPA parameterised query for following SQL statement

select * from car where (colour, speed) in ((\'red\', 50), (\'blue\', 70))


        
相关标签:
1条回答
  • 2021-01-15 18:19

    While searching, I found a very similar question here. Perhaps that's more in line with this problem.

    However, I implemented something slightly different.

    @Query("SELECT p FROM Product p "
                + "LEFT JOIN p.categories category "
                + "WHERE UPPER(p.name) LIKE UPPER(CONCAT('%', COALESCE(:searchRequest, ''), '%')) "
                + "AND UPPER(p.description) LIKE UPPER(CONCAT('%', COALESCE(:description, ''), '%')) "
                + "AND p.price BETWEEN :priceLow AND :priceHigh "
                + "AND p.averageRating >= :averageRating "
                + "AND p.archived = :archived "
                + "AND ((category.name IN :selectedCategories) "
                + "OR (:amountOfSelectedCategories = 0 AND category IN (SELECT c FROM Category c))) "
                + "GROUP BY p "
                + "HAVING SIZE(p.categories) >= :amountOfSelectedCategories"
        )
        Page<Product> findAllBySearchModel(
                Pageable pageable,
                @Param("searchRequest") String searchRequest,
                @Param("description") String description,
                @Param("priceLow") BigDecimal priceLow,
                @Param("priceHigh") BigDecimal priceHigh,
                @Param("averageRating") double averageRating,
                @Param("archived") boolean archived,
                @Param("selectedCategories") List<String> selectedCategories,
                @Param("amountOfSelectedCategories") int amountOfSelectedCategories
        );
    
    0 讨论(0)
提交回复
热议问题