QuerySyntaxException:意外的AST节点

时间:2018-08-24 10:15:40

标签: mysql spring jpql

JPQL

@Query("SELECT new com.avs.lapm.service.dto.AttendantResultDTO (attendant.id, aqa.attendant.name, SUM( CASE WHEN aqa.questionAnswer.isCorrectAnswer THEN 1 ELSE 0 END ) ) "
            + "FROM AttendantQuestionAnswer aqa WHERE aqa.attendant.id = :id GROUP BY aqa.attendant.id")
    AttendantResultDTO findAttendantResultById(@Param("id") Long id);

还有例外

原因:java.lang.IllegalArgumentException:

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: . near line 1, column 124 [SELECT new com.avs.lapm.service.dto.AttendantResultDTO (attendant.id, aqa.attendant.name, SUM( CASE WHEN aqa.questionAnswer.isCorrectAnswer THEN 1 ELSE 0 END ) )FROM com.avs.lapm.domain.AttendantQuestionAnswer aqa WHERE aqa.attendant.id = :id GROUP BY aqa.attendant.id]
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:133)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:164)
        at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:670)
        at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:23)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:350)
        at com.sun.proxy.$Proxy209.createQuery(Unknown Source)
        at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:87)
        ... 62 common frames omitted

我需要将布尔值isCorrectAnswer转换为int并将其求和。

0 个答案:

没有答案