我在 Jpql 中使用 @Query 注释,我用额外的 "distinct" 修改了我的查询,如何修复它?
I use @Query annotation in Jpql, I modified my query with additional "distinct", How to Fix it?
在我的存储库中,我用额外的 "distinct" 修改了我的查询,但它不起作用
@Query(value = "select distinct i from Item i "
+"where i.store = ?1 and i.itemVariant IN ?2 "
+"and i.status = ?3 " )
Page<Item> findByStoreAndItemVariantInAndStatus
(Store store, List<ItemVariant> itemVariant ,byte status, Pageable pageable);
如果我删除额外的修改@Query,这有效但结果是重复的
我已经修好了。我使用本机查询更改它并将不同的更改为分组依据,并且有效
@Query(value = "SELECT i.* "
+" FROM public.mst_item as i "
+" join public.mst_store as ist "
+" on i.store_id = ist.id "
+" join public.mst_item_classifiers as iv "
+" on iv.item_id = i.id "
+" where ist.id = :store and iv.name IN "
+" (select ic.name from public.mst_item_classifiers as ic "
+" where ic.name like concat('%',:itemVariant,'%') and ic.status = :status ) "
+" and i.status = :status "
+" group by ?#{#pageable}, i.id",
nativeQuery = true)
Page<Item> findByStoreAndItemVariantInAndStatus(@Param("store")Store store,@Param("itemVariant") String itemVariant , @Param("status") byte status, Pageable pageable);
在我的存储库中,我用额外的 "distinct" 修改了我的查询,但它不起作用
@Query(value = "select distinct i from Item i "
+"where i.store = ?1 and i.itemVariant IN ?2 "
+"and i.status = ?3 " )
Page<Item> findByStoreAndItemVariantInAndStatus
(Store store, List<ItemVariant> itemVariant ,byte status, Pageable pageable);
如果我删除额外的修改@Query,这有效但结果是重复的
我已经修好了。我使用本机查询更改它并将不同的更改为分组依据,并且有效
@Query(value = "SELECT i.* "
+" FROM public.mst_item as i "
+" join public.mst_store as ist "
+" on i.store_id = ist.id "
+" join public.mst_item_classifiers as iv "
+" on iv.item_id = i.id "
+" where ist.id = :store and iv.name IN "
+" (select ic.name from public.mst_item_classifiers as ic "
+" where ic.name like concat('%',:itemVariant,'%') and ic.status = :status ) "
+" and i.status = :status "
+" group by ?#{#pageable}, i.id",
nativeQuery = true)
Page<Item> findByStoreAndItemVariantInAndStatus(@Param("store")Store store,@Param("itemVariant") String itemVariant , @Param("status") byte status, Pageable pageable);