У меня есть SQL-запрос, который отлично работает в mysql workbench
но когда я конвертирую тот же запрос в 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 Workbench, но не в Hibernate, где я сохранил дополнительные ( в моем коде.
пожалуйста, помогите мне. спасибо!