爲什麼hibernate在不聯網的時候解析不了配置文件?(hibernate.cfg.xml)

在做項目時通常用hibernate框架來進行數據庫的一些操作,但是有時候網絡條件差或者不聯網的情況下,在對數據庫進行增刪改查操作時,總是會報下面的異常:

Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1418)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
	at org.wjp.hibernate.ExportDB.main(ExportDB.java:8)
	Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org
	at org.dom4j.io.SAXReader.read(SAXReader.java:484)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1408)
	... 3 more

剛開始沒注意,在沒聯網的時候報出這個錯誤。。。

在網上查詢一些資料才知道爲什麼報錯!

先看下hibernate.cfg.xml核心文件中的頭部分:

1.一般配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

2.

<?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">


我去!就是這兩東西搞得鬼。。

me使用的就是第一種配置頭文件,一沒網就報錯!!!!

原因就出現在dtd文件那裏,因爲hibernate的兩個配置文件分別都會默認去上面加粗的網站去找,所以當使用hibernate進行數據庫操作時,如果你的網絡環境不好或者沒聯網,此時配置文件無法訪問指定的dtd驗證文件,所以纔會出現xml無法解析的異常。



所以不要用第一種配置文件啦。。。。。。

第二種暫時沒發現有什麼異常之處



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章