在使用SSH框架开发过程,使用hibernate框架提供的工具类实现与数据库数据交互,在执行cmd操作时,如果出现以下异常:
org.hibernate.hql.ast.QuerySyntaxException: xxx is not mapped [from xxx] 或者
nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException
详细异常信息
::, ERROR DefaultDispatcherErrorHandler: - Exception occurred during processing request: Customer is not mapped [from Customer]; nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException: Customer is not mapped [from Customer]
org.springframework.orm.hibernate5.HibernateQueryException: Customer is not mapped [from Customer]; nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException: Customer is not mapped [from Customer]
at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:)
at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:)
at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:)
at org.springframework.orm.hibernate5.HibernateTemplate.find(HibernateTemplate.java:)
at cn.itheima.ssh_exem.dao.impl.CustomerDaoImpl.findAllCustomer(CustomerDaoImpl.java:)
at cn.itheima.ssh_exem.service.impl.CustomerServiceImpl.findAllCustomer(CustomerServiceImpl.java:)
at cn.itheima.ssh_exem.action.CustomerAction.findCustomer(CustomerAction.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:)
at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:)
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:)
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:)
at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:)
at ognl.ASTMethod.getValueBody(ASTMethod.java:)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:)
at ognl.SimpleNode.getValue(SimpleNode.java:)
at ognl.Ognl.getValue(Ognl.java:)
at ognl.Ognl.getValue(Ognl.java:)
at com.opensymphony.xwork2.ognl.OgnlUtil$.execute(OgnlUtil.java:)
at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute(OgnlUtil.java:)
at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:)
at org.springframework.orm.hibernate5.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:)
at java.lang.Thread.run(Thread.java:)
问题分析与解决:
上面的异常的抛出主要有几个方面:
1、如果你使用的xml配置文件开发方式,检查hibernate核心配置文件中是否声明映入实体类的映射文件。简单是说,使用标<mapping resource=”/项目全路径名称/映射实体类的名称.hbm.xml”>建立实体类与表的映射关系。
2、检查HQL语句书写书否正确。From 后面跟的是实体类名称而不是数据表的名称,同时注意大小写和单词拼写错误,以及不能包含中多的空格。
3、如果经过以上两步的检测,执行结果仍然报上面的错误信息,那么在你hql语句中from 后面直接跟实体类的全名称。