实体类和数据表的映射异常(XXX is not mapping[ ])

在使用SSH框架开发过程,使用hibernate框架提供的工具类实现与数据库数据交互,在执行cmd操作时,如果出现以下异常:

org.hibernate.hql.ast.QuerySyntaxException: xxx is not mapped [from xxx] 或者

nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException

详细异常信息

 

21:08:31,951 ERROR DefaultDispatcherErrorHandler:42 - 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:176)
    at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:344)
    at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:309)
    at org.springframework.orm.hibernate5.HibernateTemplate.find(HibernateTemplate.java:863)
    at cn.itheima.ssh_exem.dao.impl.CustomerDaoImpl.findAllCustomer(CustomerDaoImpl.java:26)
    at cn.itheima.ssh_exem.service.impl.CustomerServiceImpl.findAllCustomer(CustomerServiceImpl.java:22)
    at cn.itheima.ssh_exem.action.CustomerAction.findCustomer(CustomerAction.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:870)
    at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1293)
    at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
    at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117)
    at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:108)
    at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1369)
    at ognl.ASTMethod.getValueBody(ASTMethod.java:90)
    at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
    at ognl.SimpleNode.getValue(SimpleNode.java:258)
    at ognl.Ognl.getValue(Ognl.java:494)
    at ognl.Ognl.getValue(Ognl.java:458)
    at com.opensymphony.xwork2.ognl.OgnlUtil$2.execute(OgnlUtil.java:309)
    at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute(OgnlUtil.java:340)
    at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:307)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:423)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:287)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:250)
    at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
    at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:76)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:125)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:253)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:139)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.orm.hibernate5.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:151)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

问题分析与解决:

上面的异常的抛出主要有几个方面:

1、如果你使用的xml配置文件开发方式,检查hibernate核心配置文件中是否声明映入实体类的映射文件。简单是说,使用标<mapping resource=”/项目全路径名称/映射实体类的名称.hbm.xml”>建立实体类与表的映射关系。

2、检查HQL语句书写书否正确。From 后面跟的是实体类名称而不是数据表的名称,同时注意大小写和单词拼写错误,以及不能包含中多的空格。

3、如果经过以上两步的检测,执行结果仍然报上面的错误信息,那么在你hql语句中from 后面直接跟实体类的全名称。

时间: 2024-11-14 21:25:11

实体类和数据表的映射异常(XXX is not mapping[ ])的相关文章

蜗牛—实体类与数据表的映射文件

Hibernate框架可以根据你写的映射文件直接对你的实体类进行增删改查等等数据库操作.传入的可以是一个实体对象. 首先是我的实体类代码 Position.java package com.attence.entity; public class Position { private int id; private String position_Name; private String desc; public int getId() { return id; } public void se

Hibernate实体类与数据表字段默认值之间的优先关系

在日常的应用开发过程中,我们一般都会使用对象关系映射来通过面向对象的编程模型来解决数据库的操作,我们生产过程当中使用较多的当属Hibernate框架了,他非常灵活,为我们提供了多种方式来实现数据层的操作与管理.通过实体类与数据表的映射,实体类对应表,属性对应字段就可以将我们想要生产的对象赋值到数据库,但是我们有时也需要查询对象,但是无论什么操作,都必须通过实体类来传递数据. 有时我们数据库有一些字段是数据库自动赋值,禁止用户通过程序修改的,如记录生成时间,那么如果你实体类按照正常情况下,你为了查

ADO.NET(完整修改和查询、实体类,数据访问类)

一.完整修改和查询 在编写c#语句时需考虑到用户体验,例如在编写修改语句时,需要考虑到输入的内容在数据库中是否能够找到. 中间变量运用. 1.先查 2.执行操作 完整修改语句: bool has = false; Console.Write("请输入要修改的用户名:"); string Uname = Console.ReadLine(); //到数据库中查询输入的用户名是否存在 SqlConnection conn = new SqlConnection("server=.

重要!!!实体类、数据访问类

创建两个类: users类: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 实体类_数据访问类.App_Code { public class Users { private int _Ids; /// <summary> /// ids /// </summary> public int Ids { get { return _Ids;

实体类、数据访问类、属性扩展

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 实体类_数据访问类.App_Code { public class Users { private string _username; //封装 /// <summary> /// 用户名 /// </summary> public

WebForm 获取实体类的数据,填充页面(用session传值)

<1> 首先创建一个实体类 User using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace 实体类 { public class User { public int Id { get; set; } public string UserName { get; set; } public int Age { get; set; } public int Gend

ado.net 实体类_数据访问类

实体类: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 实体类_数据访问类.App_Code { public class Users { private int _code; /// <summary> /// code /// </summary> public int Code { get { return _code; } set

字符串攻击、防攻击、实体类、数据访问类

字符串攻击: 主要利用获取需用户输入的字符串时,通过输入精心编制的含有某种指令的字符串,从而对数据库进行攻击性操作. 防攻击: 例 cmd.CommandText = "update Users set [email protected],[email protected],[email protected],[email protected],[email protected],[email protected] where [email protected]"; cmd.Param

字符串攻击、防攻击、实体类、数据访问类--2016年11月29日

防止SQL数据库字符串注入攻击 SQL数据库字符串注入攻击:需要使用cmd.Parameters这个集合占位符: @key 代表这个位置用这个占位符占住了 Parameters这个集合中将此占位符所代表的数据补全 cmd.Parameters.Clear(); --添加占位符数据之前,要清空此集合cmd.Parameters.Add("@pwd", Pwd); --占位符内容填充cmd.Parameters.Add("@nname",Nname);cmd.Param