Skip to content

CountQuery fails to be auto generated when not using explicit alias [DATAJPA-1737] #2032

Closed
@spring-projects-issues

Description

@spring-projects-issues

Jonas Tänzer opened DATAJPA-1737 and commented

Consider the following repository: 

public interface BookErrorRepository extends Repository<BookError, Long> {

    @Query("FROM BookError b WHERE portal = :portal AND date >= :startDate AND date <= :endDate" +
           " AND (:search IS NULL OR keyword LIKE :search%)" +
           " AND (:state IS NULL OR errors = :#{#state?.shortMessage})")
    Page<BookError> findByPortalInDateRange(@Param("portal") Portal portal,
            @Param("startDate") LocalDate startDate,
            @Param("endDate") LocalDate endDate,
            @Param("search") Optional<String> search,
            @Param("state") Optional<State> state,
            Pageable pageable);

}

When changing this to 

FROM BookError WHERE portal [...]

the attached exception occurs on startup.

At first it seems like an issue with the HQL parser, but upon further inspection it seems that spring-data-jpa doesn't generate the count query correctly, because it recognizes WHERE as the alias. 

Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: WHERE near line 1, column 14 [select count(WHERE) FROM com.example.project

This isn't a huge issue issue of course, but I figured I'd report to at least receive feedback anyway.

 

 


Attachments:

Metadata

Metadata

Labels

in: query-parserEverything related to parsing JPQL or SQLtype: bugA general bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions