我对在JPA查询中使用IN子句有一个问题.当O使用c.id IN (1,7)
时,它工作得很好,但当我使用c.id IN :categories
时,它会给我这个错误:
Org.hibernate.type.descriptor.java.CoercionException:无法强制值[1,7][java.util.Array$ArrayList]
@Query("SELECT new com.example.events.dto.Event.ParticipantGetAllEventsDto(e, COUNT(p)) "
+ "FROM Event e JOIN FETCH e.reservation r JOIN FETCH r.salon s "
+ "LEFT JOIN r.participants p "
+ "JOIN e.categories c "
+ "WHERE (:title is null OR e.title LIKE %:title%) AND "
+ "(:isFree is null OR ((:isFree = true AND e.cost = 0) OR (:isFree = false AND e.cost >0 ))) AND "
+ "(:categories is null OR c.id IN (:categories) ) "
+ "GROUP BY e")
List<ParticipantGetAllEventsDto> getAll(@Param("title") String title,@Param("categories") List<Long> categories ,@Param("isFree") boolean isFree);
我也查了一下categories
的S的值:它是一个arrayList
,值是[1,7]