java.lang.IllegalArgumentException:org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌:((带有子查询)

时间:2018-07-03 10:05:23

标签: mysql hibernate

我有一个可以在mysql workbench中完美运行的sql查询 但是当我将相同的查询转换为hibernate hql时,会出现以下异常

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ( near line 1, column 22 [SELECT COUNT(*) FROM (  SELECT pd.studentAdmissionId,SUM(fcm.feeAmount) - COALESCE(ft.amountPaid, 0)  AS due_amount  FROM com.rasvek.cg.entity.StudentPresentClassDetails pd INNER JOIN com.rasvek.cg.entity.FeeClassMapping fcm  ON pd.classId = fcm.classId  LEFT JOIN ( SELECT ft.studentDetails.studentAdmissionId ,SUM(ft.amountPaid) amount_paid  FROM   com.rasvek.cg.entity.FeeTransactions ft GROUP BY ft.studentDetails.studentAdmissionId ) ft ON ft.studentDetails.studentAdmissionId=pd.studentAdmissionId GROUP BY  pd.studentAdmissionId ) t  WHERE t.due_amount > 0]
    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.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:103)
    at com.rasvek.cms.dao.MasterDaoImpl.getFeeDueCount(MasterDaoImpl.java:3951)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)

请查看查询

Query   query = currentSession.createQuery("SELECT COUNT(*) FROM ("
        + "  SELECT pd.studentAdmissionId"
        + ",SUM(fcm.feeAmount) - COALESCE(ft.amountPaid, 0)  AS due_amount "
        + " FROM StudentPresentClassDetails pd "
        + "INNER JOIN FeeClassMapping fcm  ON pd.classId = fcm.classId  "
        + "LEFT JOIN ("
        + " SELECT ft.studentDetails.studentAdmissionId ,SUM(ft.amountPaid) amount_paid "
        + " FROM   FeeTransactions ft "
        + "GROUP BY ft.studentDetails.studentAdmissionId "
        + ") ft ON ft.studentDetails.studentAdmissionId=pd.studentAdmissionId"
        + " GROUP BY  pd.studentAdmissionId ) t "
        + " WHERE t.due_amount > 0");

其中有什么问题,它可以在mysql工作台中完美运行,但不能在休眠状态下在代码中保留额外的)。

请帮助我。谢谢!。

0 个答案:

没有答案