org.hibernate.hql.internal.ast.QuerySyntaxException: неожиданный токен (asf является псевдонимом для таблицы) - PullRequest
0 голосов
/ 06 июня 2018

я написал запрос гибернации, чтобы получить подробности из нескольких таблиц следующим образом

Query       query = currentSession.createQuery("select s.studentAdmissionId as studentAdmissionId, pd.rollNum as rollNum ,s.firstname as firstName , s.lastname as lastName , m.className as className,"
                    + "sec.sectionName as sectionName,sum(fcm.feeAmount) as totalAmount from StudentDetails s, StudentPresentClassDetails pd, MasterCampusClass m ,"
                    + "MasterCampusSection sec ,FeeClassMapping fcm,AssocFeeStudent afs where "
                    + "pd.studentAdmissionId = afs.studentDetails.studentAdmissionId"
                    + "and afs.feeCategory.feeCatId=fcm.feeCategory.feeCatId"
                    + "and s.studentAdmissionId =afs.studentDetails.studentAdmissionId"
                    + "and m.classId=pd.classId"
                    + "and  pd.presentSectionId = sec.sectionId"
                    + "and fcm.masterCampusClass.classId=pd.classId group by afs.studentDetails.studentAdmissionId");

я получаю следующее исключение

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: afs near line 1, column 554 [select s.studentAdmissionId as studentAdmissionId, pd.rollNum as rollNum ,s.firstname as firstName , s.lastname as lastName , m.className as className,sec.sectionName as sectionName,sum(fcm.feeAmount) as totalAmount from com.rasvek.cg.entity.StudentDetails s, com.rasvek.cg.entity.StudentPresentClassDetails pd, com.rasvek.cg.entity.MasterCampusClass m ,com.rasvek.cg.entity.MasterCampusSection sec ,com.rasvek.cg.entity.FeeClassMapping fcm,com.rasvek.cg.entity.AssocFeeStudent afs where pd.studentAdmissionId = afs.studentDetails.studentAdmissionIdand afs.feeCategory.feeCatId=fcm.feeCategory.feeCatIdand s.studentAdmissionId =afs.studentDetails.studentAdmissionIdand m.classId=pd.classIdand  pd.presentSectionId = sec.sectionIdand fcm.masterCampusClass.classId=pd.classId group by afs.studentDetails.studentAdmissionId]
    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.getListOfStudentOfTransactions(MasterDaoImpl.java:2192)
    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)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy51.getListOfStudentOfTransactions(Unknown Source)
    at com.rasvek.cms.service.MasterSeviceImpl.getListOfStudentOfTransactions(MasterSeviceImpl.java:675)
    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)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy52.getListOfStudentOfTransactions(Unknown Source)
    at com.rasvek.cms.controller.StudentController.getListOfStudentOfTransactions(StudentController.java:1428)
    at com.rasvek.cms.controller.StudentController$$FastClassBySpringCGLIB$$cb2af793.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
    at com.rasvek.cms.controller.StudentController$$EnhancerBySpringCGLIB$$f7295207.getListOfStudentOfTransactions(<generated>)
    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)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: afs near line 1, column 554 [select s.studentAdmissionId as studentAdmissionId, pd.rollNum as rollNum ,s.firstname as firstName , s.lastname as lastName , m.className as className,sec.sectionName as sectionName,sum(fcm.feeAmount) as totalAmount from com.rasvek.cg.entity.StudentDetails s, com.rasvek.cg.entity.StudentPresentClassDetails pd, com.rasvek.cg.entity.MasterCampusClass m ,com.rasvek.cg.entity.MasterCampusSection sec ,com.rasvek.cg.entity.FeeClassMapping fcm,com.rasvek.cg.entity.AssocFeeStudent afs where pd.studentAdmissionId = afs.studentDetails.studentAdmissionIdand afs.feeCategory.feeCatId=fcm.feeCategory.feeCatIdand s.studentAdmissionId =afs.studentDetails.studentAdmissionIdand m.classId=pd.classIdand  pd.presentSectionId = sec.sectionIdand fcm.masterCampusClass.classId=pd.classId group by afs.studentDetails.studentAdmissionId]
    at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74)
    at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:91)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:291)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:186)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:141)
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115)
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
    at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)
    at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:553)
    at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:662)
    ... 88 more

что не так в моем запросе

насколько я знаю, я сохранил afs, что является псевдонимом для AssocFeeStudent, но я получаю вот так unexpected token: afs near line 1

что не так, я не могу отследить это, пожалуйста, помогите мне.

спасибо!.

Ответы [ 2 ]

0 голосов
/ 06 июня 2018

Между концом одной строки в запросе и началом следующей нет пробела.

Попробуйте:

Query       query = currentSession.createQuery("select s.studentAdmissionId as studentAdmissionId, pd.rollNum as rollNum ,s.firstname as firstName , s.lastname as lastName , m.className as className, "
                + "sec.sectionName as sectionName,sum(fcm.feeAmount) as totalAmount from StudentDetails s, StudentPresentClassDetails pd, MasterCampusClass m , "
                + "MasterCampusSection sec ,FeeClassMapping fcm,AssocFeeStudent afs where "
                + "pd.studentAdmissionId = afs.studentDetails.studentAdmissionId "
                + "and afs.feeCategory.feeCatId=fcm.feeCategory.feeCatId "
                + "and s.studentAdmissionId =afs.studentDetails.studentAdmissionId "
                + "and m.classId=pd.classId "
                + "and  pd.presentSectionId = sec.sectionId "
                + "and fcm.masterCampusClass.classId=pd.classId group by afs.studentDetails.studentAdmissionId");
0 голосов
/ 06 июня 2018

Я решил это, написав запрос в одну строку следующим образом

Query       query = currentSession.createQuery("select s.studentAdmissionId as studentAdmissionId, pd.rollNum as rollNum ,s.firstname as firstName , s.lastname as lastName , m.className as className,sec.sectionName as sectionName,sum(fcm.feeAmount) as totalAmount from StudentDetails s, StudentPresentClassDetails pd, MasterCampusClass m ,MasterCampusSection sec ,FeeClassMapping fcm,AssocFeeStudent afs where pd.studentAdmissionId = afs.studentDetails.studentAdmissionId and afs.feeCategory.feeCatId=fcm.feeCategory.feeCatId and s.studentAdmissionId =afs.studentDetails.studentAdmissionId and m.classId=pd.classId and  pd.presentSectionId = sec.sectionId and fcm.masterCampusClass.classId=pd.classId group by afs.studentDetails.studentAdmissionId"); 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...