1. 程式人生 > >hibernate對映檔案頭資訊使用問題

hibernate對映檔案頭資訊使用問題

在使用hibernate時,因為對映檔案的頭資訊是:

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

執行時報錯:
java.lang.ExceptionInInitializerError

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource
 [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document 
from input stream

問題解決,是資料表的配置檔案(*.hbm.xml)的標頭檔案的錯,原來的程式碼是:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
聯網的時候,專案會在網路上查詢3.0的dtd檔案;而斷網的時候,專案找不到相應的dtd檔案,就會報錯。

把頭資訊改為:

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
這樣在斷網的情況下就不會出錯了