hibernate之无法解析hibernate.cfg.xml

来源:互联网 发布:ios安卓数据互通的游戏 编辑:程序博客网 时间:2024/05/17 03:40

刚开始学习hibernate,在写完java对象、配置hibernate相关xml后,通过客户端调用时,程序报出以下异常: 

Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2013) at org.hibernate.cfg.Configuration.configure(Configuration.java:1925) at org.hibernate.cfg.Configuration.configure(Configuration.java:1904) at com.lvaj.examples.example1.Client.main(Client.java:10)Caused by: org.dom4j.DocumentException: Error on line 4 of document  : The system identifier must begin with either a single or double quote character. Nested exception: The system identifier must begin with either a single or double quote character. at org.dom4j.io.SAXReader.read(SAXReader.java:482) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2005) ... 3 more

根据异常内容在hibernate.cfg.xml文件排查,最后发现原来是犯了一个低级错误,即hibernate.cfg.xml文件的头部分漏写了。原内容(错误内容)为:

<!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD 3.0//EN"


 

正确的头内容为:

<!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">


果然是细节决定成败啊!