• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
java小斌
让技术填满空虚的内心世界
博客园    首页    新随笔    联系   管理    订阅  订阅

Could not parse mapping document from input stream

问题描述:最近在整合ssh的时候出现的一个报错如下:

Could not parse mapping document from input stream

Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream

....

Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org

在出现这个错误的时候因为没有什么具体的提示,所以也没有什么头绪去改,然后就各种百度,百度到的最多的答案就是:

1、Person.hbm.xml配置文件中,"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">改为: "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"

2、定义的类名或属性名不对,如:*.hbm.xml文件中属性name对应的实体类name不一致。

但是我改完之后还是不对,最后发现问题出现在了applicationContext.xml文件中,在项目中我hibernate使用的是hibernate3.0版本,而我一开始在配置sessionFactory时写成了hibernate4,所以导致了后来一直读取失败的。

解决办法:

 1 <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
 2         <property name="dataSource" ref="dataSource"></property>
 3         <property name="mappingResources">
 4             <list>
 5                 <value>cn/xyp/web/entity/User.hbm.xml</value>
 6             </list>
 7         </property>
 8         <property name="hibernateProperties">
 9             <props>
10                 <prop key="hibernate.show_sql">true</prop>
11                 <prop key="hibernate.hbm2ddl.auto">true</prop>
12                 <prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>
13                 <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
14                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
15             </props>
16         </property>
17     </bean>

将org.springframework.orm.hibernate4.LocalSessionFactoryBean和org.springframework.orm.hibernate4.SpringSessionContext中hibernate4改为你项目中对应的hibernate版本,我这里是改为了hibernate3,问题解决。

 

posted @ 2018-08-15 11:13  Java小斌  阅读(418)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3