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,问题解决。

 

转载于:https://www.cnblogs.com/lihuibin/p/9480307.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值