hibernate之无法解析hibernate.cfg.xml

刚开始学习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">


果然是细节决定成败啊!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值