关于Spring整合Hibernate,映射实体类is not mapped

问题描述

用了两种方式:1、<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="dataSource"><refbean="dataSource"/></property><propertyname="hibernateProperties"><props><propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop></props></property><propertyname="mappingResources"><list><value>vo/Customer.hbm.xml</value></list></property></bean>

不可行,报错没有找到映射2、<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="configLocation"value="classpath:config/hibernate.cfg.xml"></property><propertyname="dataSource"><refbean="dataSource"/></property><propertyname="hibernateProperties"><props><propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop></props></property></bean>

hibernate.cfg.xml中:<mappingresource="vo/Customer.hbm.xml"/>可行,可以执行成功搞不懂为什么第一种方式不行,求解

解决方案

解决方案二:
你把mappingResources那一段放到hibernateProperties上面试试。
解决方案三:
试过了还是不行严重:Servlet.service()forservlet[default]incontextwithpath[/MyWork]threwexception[org.hibernate.hql.ast.QuerySyntaxException:Customerisnotmapped[fromCustomerwherecustname='asd']]withrootcauseorg.hibernate.hql.ast.QuerySyntaxException:Customerisnotmapped[fromCustomerwherecustname='asd']
解决方案四:
我以前的项目这样写是好的,你参考一下:<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="dataSource"><reflocal="dataSource"/></property><propertyname="mappingResources"><list><value>com/ql/entity/User.hbm.xml</value><value>com/ql/entity/Student.hbm.xml</value></list></property><propertyname="hibernateProperties"><value>hibernate.show_sql=truehibernate.dialect=org.hibernate.dialect.MySQLDialecthibernate.cache.use_second_level_cache=truehibernate.cache.provider_class=org.hibernate.cache.OSCacheProviderhibernate.generate_statistics=truehibernate.connection.release_mode=autohibernate.autoReconnect=true</value></property></bean>

解决方案五:
引用1楼wlwlwlwl015的回复:

你把mappingResources那一段放到hibernateProperties上面试试。

试过了还是不行严重:Servlet.service()forservlet[default]incontextwithpath[/MyWork]threwexception[org.hibernate.hql.ast.QuerySyntaxException:Customerisnotmapped[fromCustomerwherecustname='asd']]withrootcauseorg.hibernate.hql.ast.QuerySyntaxException:Customerisnotmapped[fromCustomerwherecustname='asd']
解决方案六:
路径写全,也许是路径不对,没加载到hbm配置文件。
解决方案七:
引用3楼wlwlwlwl015的回复:

我以前的项目这样写是好的,你参考一下:<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="dataSource"><reflocal="dataSource"/></property><propertyname="mappingResources"><list><value>com/ql/entity/User.hbm.xml</value><value>com/ql/entity/Student.hbm.xml</value></list></property><propertyname="hibernateProperties"><value>hibernate.show_sql=truehibernate.dialect=org.hibernate.dialect.MySQLDialecthibernate.cache.use_second_level_cache=truehibernate.cache.provider_class=org.hibernate.cache.OSCacheProviderhibernate.generate_statistics=truehibernate.connection.release_mode=autohibernate.autoReconnect=true</value></property></bean>

多谢回答,但是还是报同样的错以下是我修改后的↓<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="dataSource"><refbean="dataSource"/></property><propertyname="mappingResources"><list><value>vo/Customer.hbm.xml</value></list></property><propertyname="hibernateProperties"><value>hibernate.dialect=org.hibernate.dialect.MySQLDialect</value></property></bean>

解决方案八:
引用5楼wlwlwlwl015的回复:

路径写全,也许是路径不对,没加载到hbm配置文件。

vo已经是src下最外层目录了
解决方案九:
真心求解,虽然用第二种方式可行,但是一直身怀一颗打破砂锅问到底的心,况且刚刚接触SSH,对我以后的学习很有用,希望大家发表各自见解,多谢!
解决方案十:
加上classpath:如下:<propertyname="mappingLocations"><list><value>classpath:vo/Customer.hbm.xml</value><value>classpath:vo/Customer.hbm.xml</value></list></property>
解决方案十一:
<propertyname="mappingLocations"><list><value>classpath:/你的路径/你的路径/*.hbm.xml</value></list></property>

试试通配符方式,匹配你某个文件夹下面的所有以hbm.xml结尾的文件
解决方案十二:
引用9楼gudu1289的回复:

加上classpath:如下:<propertyname="mappingLocations"><list><value>classpath:vo/Customer.hbm.xml</value><value>classpath:vo/Customer.hbm.xml</value></list></property>

也试过了↓,还是报同样错误<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="dataSource"><refbean="dataSource"/></property><propertyname="hibernateProperties"><value>hibernate.dialect=org.hibernate.dialect.MySQLDialect</value></property><propertyname="mappingLocations"><list><value>classpath:vo/Customer.hbm.xml</value></list></property></bean>

解决方案十三:
引用10楼applewings2014的回复:

<propertyname="mappingLocations"><list><value>classpath:/你的路径/你的路径/*.hbm.xml</value></list></property>

试试通配符方式,匹配你某个文件夹下面的所有以hbm.xml结尾的文件

错误还是一样,报没有映射Customer类严重:Servlet.service()forservlet[default]incontextwithpath[/MyWork]threwexception[org.hibernate.hql.ast.QuerySyntaxException:Customerisnotmapped[fromCustomerwherecustname='zxc']]withrootcauseorg.hibernate.hql.ast.QuerySyntaxException:Customerisnotmapped[fromCustomerwherecustname='zxc']atorg.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)atorg.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)atorg.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)atorg.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:277)atorg.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)atorg.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)atorg.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)

解决方案十四:
多谢大家提出的可行性分析!如果需要我提供其他配置文件,请随时回帖!多谢!
解决方案十五:
是MyEclipse生成的文件吗?我记得有一个版本它生成映射文件的DTD末尾多了一个空格,所以会出问题!
解决方案:
应该是路径的问题
解决方案:
引用14楼u012171905的回复:

是MyEclipse生成的文件吗?我记得有一个版本它生成映射文件的DTD末尾多了一个空格,所以会出问题!

不是用MyEclipse生成的框架,是我手动敲的。。。
解决方案:
引用15楼u010808697的回复:

应该是路径的问题

目录层次结构很简单的,应该不是路径问题。。。

时间: 2024-07-30 20:25:08

关于Spring整合Hibernate,映射实体类is not mapped的相关文章

hibernate映射实体类路径问题

问题描述 hibernate映射实体类路径问题 我建了一个source fold 命名src/main/java,里面建了一个包entity,entity里面有2个实体类 现在在hibernate.cfg.xml中 class路径改怎么写? 在线等

hibernate注解实体类对应数据库字段,出了问题?请教

问题描述 hibernate注解实体类对应数据库字段,出了问题?请教 我在用注解写对应数据库的映射文件时候 搞了个单元测试 结果就报了异常 : org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonDao': Autowiring of fields failed; nested exception is org.springframework.beans.fac

spring整合hibernate出现sessionFactory的bean创建异常错误

问题描述 spring整合hibernate出现sessionFactory的bean创建异常错误 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; neste

java实体类-java 映射实体类使用

问题描述 java 映射实体类使用 从数据库根据表映射生成一个实体类,这个类如何使用 ,因为我没办法引用啊 设定参数值后 那要怎么传参取参等等... 解决方案 把问题再具体化下,你想在哪引用.传值是从哪传到哪 解决方案二: 我不知道怎么回答这个问题,我觉得问的很不清晰. 首先你有没有使用框架,比如hibernate.mybaits 等. 如果没有,你的映射指的是什么,比如hibernate 映射关系通过xml配置.或注解等,所谓的映射是,框架帮你处理好类与数据库之间的关系. 你需要有处理这些的业

ssh整合-spring整合hibernate做测试时没有报错,当三个整合时启动就报错啦,求大神指点!!

问题描述 spring整合hibernate做测试时没有报错,当三个整合时启动就报错啦,求大神指点!! 报的错误org.springframework.scheduling.quartz.JobMethodInvocationFailedException: Invocation of method 'ecsUnsigned' on target class [class $Proxy17] failed; nested exception is org.springframework.tran

spring 整合hibernate出错

问题描述 spring 整合hibernate出错 <?xml version ="1.0" encoding ="utf-8"?> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.

java-测试Spring整合hibernate/Struts2框架时,配置文件报奇怪的错误,求解

问题描述 测试Spring整合hibernate/Struts2框架时,配置文件报奇怪的错误,求解 为什么会报无法识别property? 解决方案 怎么都是这种问题,property要包含在bean标签内 解决方案二: Struts2+hibernate+spring整合时错误Struts2+hibernate+spring整合时错误 解决方案三: http://iteye.blog.163.com/blog/static/186308096201210265334689/ 解决方案四: pro

spring整合hibernate出错!!!

问题描述 spring整合hibernate出错!!! 老是报图片中的错误,不知道是不是版本的问题,我的是jdk1.8.求大神们给我解决下,感激不尽!!! 解决方案 应该是哪里的路径配置不对吧,检查下hibernate.cfg.xml和applicationContext.xml,全限定名写没写错. 解决方案二: 如果是spring和mybatis整合,可参考:http://git.oschina.net/wangkang/llsfw 希望能够帮到你. 解决方案三: 看下你的配置文件怎么写的,,

hibernate映射数据库表结构不能映射实体类的原因是?

问题描述 数据库表结构,主外键关系都建好了,就是在Hibernate映射数据库表结构时,Hibernate不能映射出实体对象,而是把外键的字段映射出变量,请问大家这是什么原因? 解决方案 解决方案二:.hibernate.就是这样的.ClassA与ClassB1:N关系A.中的属性就会多一个集合SetB的变量.,方便操作不需要写复杂的sql直接调用就可以的到所属B集合