查询构建不正确用于全文搜索的Spring Data JPA存储库

时间:2017-07-26 06:45:20

标签: java spring postgresql jpa

我正在尝试使用Spring引导应用程序中的PostGreSQL数据库进行全文搜索。

以下是我为全文搜索撰写的查询。

public interface ProductSubCategoryRepository extends JpaRepository<ProductSubCategory, Long>{

           @Query(name = "SELECT product_category, product_subcategory, "
            + "product_level_category, product, product_attribute "
            + "FROM public.product_category "
            + "INNER JOIN public.product_subcategory "
            + "ON (product_category.id = product_subcategory.product_category_id) "
            + "INNER JOIN public.product_level_category "
            + "ON (product_subcategory.id = product_level_category.product_sub_category_id) "
            + "INNER JOIN public.product "
            + "ON (product_level_category.id = product.product_level_category_id) "
            + "INNER JOIN product_attribute "
            + "ON (product.id = product_attribute.product_id) "
            + "WHERE to_tsvector(product.name) @@ to_tsquery(:query) "
            + "OR to_tsvector(product_attribute.name) @@ to_tsquery(:query) "
            + "OR to_tsvector(product_level_category.name) @@ to_tsquery(:query) "
            + "OR to_tsvector(product_subcategory.name) @@ to_tsquery(:query)", nativeQuery = true)
            public List<ProductSubCategory> findProductSubCategoriesByName(@Param("query") String query);
    }

但是在数据库GUI工具(pgAdmin)上运行以下查询时。它取得了一些成果。但是当我尝试这个类似的查询时,没有结果。

控制台日志显示我错误地创建了查询

2017-07-26 11:37:18.439 DEBUG 6332 --- [nio-8000-exec-3] org.hibernate.SQL                        : select productsub0_.id as id1_12_, productsub0_.name as name2_12_, productsub0_.product_category_id as product_4_12_, productsub0_.sub_category_description as sub_cate3_12_ from public.product_subcategory productsub0_ where productsub0_.name=?
2017-07-26 11:37:18.440 TRACE 6332 --- [nio-8000-exec-3] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [VARCHAR] - [mid]

0 个答案:

没有答案