java.lang.IllegalArgumentException:org.hibernate.QueryException:没有节点的数据类型:org.hibernate.hql.internal.ast.tree.MethodNode

时间:2018-06-11 07:10:25

标签: java hibernate hql

我正在尝试追踪这个例外但不了解它,请查看我的exception并告诉我哪里出错了

java.lang.IllegalArgumentException: org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode 
 \-[METHOD_CALL] MethodNode: '('
    +-[METHOD_NAME] IdentNode: 'STR_TO_DATE' {originalText=STR_TO_DATE}
    \-[EXPR_LIST] SqlNode: 'exprList'
       +-[DOT] DotNode: 'feetermdat4_.date' {propertyName=date,dereferenceType=PRIMITIVE,getPropertyPath=date,path=ff.date,tableAlias=feetermdat4_,className=com.rasvek.cg.entity.FeeTermDates,classAlias=ff}
       |  +-[ALIAS_REF] IdentNode: 'feetermdat4_.tdm_id' {alias=ff, className=com.rasvek.cg.entity.FeeTermDates, tableAlias=feetermdat4_}
       |  \-[IDENT] IdentNode: 'date' {originalText=date}
       \-[QUOTED_STRING] LiteralNode: ''%d/%m/%Y''
 [select STR_TO_DATE(ftd.date, '%d/%m/%Y') as installmentDate,sum(fi.amount) as installmentAmount  from com.rasvek.cg.entity.AssocFeeStudent afs,com.rasvek.cg.entity.FeeTermDates ftd ,com.rasvek.cg.entity.FeeClassMapping fcm ,com.rasvek.cg.entity.FeeIntallments  fi where fcm.feeCategory.feeCatId= :fcmFeeCatId and  fi.feeClassMappingId=fcm.feeClassMappingId and afs.feeCategory.feeCatId= :afsFeeCatId  and afs.studentDetails.studentAdmissionId= :studentAdmissionId  and fi.termDateId=ftd.tdmId and STR_TO_DATE(fi.termDate, '%d/%m/%Y') <= ( select STR_TO_DATE(ff.date, '%d/%m/%Y')  from com.rasvek.cg.entity.FeeTermDates ff  where ff.tdmId= :ffTdmId) order by STR_TO_DATE(ftd.date, '%d/%m/%Y') asc]
    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.getNewpaymentByStuIdNTermId(MasterDaoImpl.java:2531)
    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.$Proxy548.getNewpaymentByStuIdNTermId(Unknown Source)
    at com.rasvek.cms.service.MasterSeviceImpl.getNewpaymentByStuIdNTermId(MasterSeviceImpl.java:710)
    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.$Proxy549.getNewpaymentByStuIdNTermId(Unknown Source)
    at com.rasvek.cms.controller.MasterController.getNewpaymentByStuIdNTermId(MasterController.java:1907)
    at com.rasvek.cms.controller.MasterController$$FastClassBySpringCGLIB$$c2eff8c2.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.MasterController$$EnhancerBySpringCGLIB$$7421bf48.getNewpaymentByStuIdNTermId(<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)

我能够理解它,在我看来一切正确,但我超越了异常。

请查看我的查询:

select
  STR_TO_DATE(ftd.date, '%d/%m/%Y') as installmentDate,
  sum(fi.amount)                    as installmentAmount
from AssocFeeStudent afs, FeeTermDates ftd, FeeClassMapping fcm, FeeIntallments fi
where
  fcm.feeCategory.feeCatId = :fcmFeeCatId and fi.feeClassMappingId = fcm.feeClassMappingId and afs.feeCategory.feeCatId = :afsFeeCatId and
  afs.studentDetails.studentAdmissionId = :studentAdmissionId and fi.termDateId = ftd.tdmId and
  STR_TO_DATE(fi.termDate, '%d/%m/%Y') <= (select STR_TO_DATE(ff.date, '%d/%m/%Y')
                                           from FeeTermDates ff
                                           where ff.tdmId = :ffTdmId)
order by STR_TO_DATE(ftd.date, '%d/%m/%Y') asc

以上查询在我看来是正确的,但有些出错了。 但是同样的查询在我的mysql WorkBench中完美运行。

3 个答案:

答案 0 :(得分:0)

问题是您正在尝试使用Hibernate query language不支持的STR_TO_DATE SQL函数。

您可能希望使用Hibernate的native query support而不是使用HQL,这样就可以执行纯SQL

List<Object[]> result = entityManager.createNativeQuery("your query here")
                            .getResultList();

但是,你将在这里放弃ORM的好处,并将结果输入标量值列表中。

但您根本不需要使用STR_TO_DATE转换日期,您可以直接将Date个实例用作HQL查询中的参数,即

session.createQuery("from FeeIntallments fi where where fi.termDateId >= :date")
                .setParameter("date", new Date())
                .list()

答案 1 :(得分:0)

我使用DATE_FORMAT(STR_TO_DATE(ftd.date, '%d/%m/%Y'),'%d/%b/%Y') 解决了以下问题

using (SqlConnection connection = new SqlConnection(connectionString))
{
    connection.Open();

    string CmdString = "select ProductID from Product where ModelNo='" + 
    comboModel.SelectedItem.ToString() + "'";
    SqlCommand cmd = new SqlCommand(CmdString, connection);
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    DataTable dt1 = new DataTable("Product");

    sda.Fill(dt1);

    foreach (DataRow dr in dt1.Rows)
    {
        txtProductID.Text = dr["ProductID"].ToString();
    }
}

答案 2 :(得分:0)

在我的情况下,发生此错误是因为我使用自定义标准扩展了方言,在该标准中注册了Postres特定的全文本搜索功能,然后忘记在测试yaml文件中指定此自定义方言。因此,它无法识别ts_rank等自定义函数。