我在where
子句中使用case语句时遇到了一些问题。如果有人知道如何解决,请帮助我!谢谢。
@Query("select e from EventTeamPlayer etp "
+ "join etp.event e "
+ "left join e.leagueTournament lt "
+ "left join lt.sportCategory sc "
+ "left join e.sport s "
+ "left join etp.homeTeamPlayer htpl "
+ "left join etp.awayTeamPlayer atpl "
+ "left join lt.country c "
+ "left join e.eventStatus es "
+ "where (e.startDate >= :startDate and e.startDate <= :endDate) "
+ "and lt.id = :leagueTournamentId "
+ "and (lt.defaultName like :searchTerm or "
+ "s.name like :searchTerm or "
+ "htpl.name like :searchTerm or "
+ "atpl.name like :searchTerm or "
+ "e.id like :searchTerm) and "
+ "(case when (:minDate is not null and :maxDate is not null) "
+ " then (e.startDate >=:minDate and e.startDate<=:maxDate) else true end) = true")
Page<Event> getEventsForWebAdmin(Pageable pageable,
@Param("searchTerm") String searchTerm,
@Param("leagueTournamentId") int leagueTournamentId,
@Param("startDate") Date startDate,
@Param("endDate") Date endDate,
@Param("minDate") Date minDate,
@Param("maxDate") Date maxDate);
以下是日志中的错误:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: 在第1行,第589列附近发现意外的AST节点: and [select e from com.itengine.bettinggateway.dao.EventTeamPlayer etp join etp.event e left join e.leagueTournament lt left join lt.sportCategory sc left join e.sport s left join etp.homeTeamPlayer htpl left join etp.awayTeamPlayer atpl left join lt.country c left join e.eventStatus es where (e.startDate >= :startDate and e.startDate <= :endDate) and (lt.defaultName like :searchTerm or s.name like :searchTerm or htpl.name like :searchTerm or atpl.name like :searchTerm or e.id like :searchTerm) and (case when (:minDate is not null and :maxDate is not null) then (e.startDate >=:minDate and e.startDate<=:maxDate) else true end) = true and lt.id = :leagueTournamentId]