码迷,mamicode.com
首页 > 移动开发 > 详细

org.hibernate.MappingException: invalid configuration

时间:2015-02-04 21:53:22      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:hibernate

写hibernate的hello world
内容非常简单,一个实体bean--Student.java
一个测试文件--StudentTest.java
两个配置文件:Student.hbm.xml,hibernate.cfg.xml


可是一直报错:
Exception in thread "main" org.hibernate.MappingException: invalid configuration
Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 25; 文档无效: 找不到语法。


我实在是很困惑啊,都简单到不能简单的东西,还报错,也分明知道是配置文件的错,后来又怀疑是jar包的问题,有怀疑是测试写错了。


今天晚上myeclipse突发善心,居然给我很详细的提示,明确指出是hibernate.cfg.xml的第二行出错。


我于是去hibernate的参考文档中把他们的配置文件整个考过来,然后修改,再测试居然华丽丽的通过了。。


果然是hibernate.cfg.xml的文件头出错了。


原来的文件头是:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration
        xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
        xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


修改之后的是:
<?xml version=‘1.0‘ encoding=‘utf-8‘?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


结论:
再也不能去其他地方乱考配置文件了,之前的配置文件就是我从一个项目里复制过来的。还是直接去文档里找比较好。

org.hibernate.MappingException: invalid configuration

标签:hibernate

原文地址:http://blog.csdn.net/lyy98521/article/details/43492983

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!