2011-06-29 44 views
4

我正在爲大學編寫一個簡單的Swing應用程序,並使用Hibernate和Oracle XE。無法讀取模式文檔'http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd

我堅持與錯誤:

29.06.2011 14:54:10 org.hibernate.cfg.annotations.Version <clinit> 
INFO: Hibernate Annotations 3.3.1.GA 
29.06.2011 14:54:10 org.hibernate.cfg.Environment <clinit> 
INFO: Hibernate 3.2.5 
29.06.2011 14:54:10 org.hibernate.cfg.Environment <clinit> 
INFO: hibernate.properties not found 
29.06.2011 14:54:10 org.hibernate.cfg.Environment buildBytecodeProvider 
INFO: Bytecode provider name : cglib 
29.06.2011 14:54:10 org.hibernate.cfg.Environment <clinit> 
INFO: using JDK 1.4 java.sql.Timestamp handling 
29.06.2011 14:54:10 org.hibernate.ejb.Version <clinit> 
INFO: Hibernate EntityManager 3.3.2.GA 
29.06.2011 14:54:31 org.hibernate.ejb.packaging.PersistenceXmlLoader$ErrorLogger warning 
WARNING: Warning parsing XML: XML InputStream(2) schema_reference.4: Failed to read schema document 'http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the  document is not <xsd:schema>. 
29.06.2011 14:54:52 org.hibernate.ejb.packaging.PersistenceXmlLoader$ErrorLogger warning 

我的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> 
    <persistence-unit name="airportPU"> 
    <provider>org.hibernate.ejb.HibernatePersistence</provider> 
    <class>my.airport.model.Crew</class> 
    <class>my.airport.model.Country</class> 
    <class>my.airport.model.City</class> 
    <class>my.airport.model.Plane</class> 
    <class>my.airport.model.Model</class> 
    <class>my.airport.model.Passenger</class> 
    <class>my.airport.model.Role</class> 
    <class>my.airport.model.Airport</class> 
    <class>my.airport.model.Spec</class> 
    <class>my.airport.model.AverageFlightTime</class> 
    <class>my.airport.model.CrewInTheRoleOnTheFlight</class> 
    <class>my.airport.model.Flight</class> 
    <class>my.airport.model.PassengersOnTheFlight</class> 
    <properties>  
     <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@172.16.0.3:1521:XE"/> 
     <property name="javax.persistence.jdbc.password" value="AIRPORT"/> 
     <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/> 
     <property name="javax.persistence.jdbc.user" value="AIRPORT"/> 
    </properties> 
    </persistence-unit> 
</persistence> 

創建實體管理器工廠:

public static EntityManagerFactory emf; 
public static EntityManager em; 
static { 
try { 
    emf = Persistence.createEntityManagerFactory("airportPU"); 
    em = emf.createEntityManager(); 
} catch (Exception e) {  
    System.exit(1); 
} 
} 

回答

8

底線:加入這行到/ etc/hosts文件來解決這個:

127.0.0.1 java.sun.com 

似乎休眠認識到這一點和其他「標準」 XSD-S的東西有,並且有沒有問題工作其內部拷貝沒有互聯網接入。

當XSD的HTTP GET不成功時出現問題,但也不會失敗: 返回其他內容或需要永久響應。 休眠不適合這些情況。 現在,URL需要永久響應,而且Hibernate不像現在這樣應用快速超時。

沒有互聯網接入的系統不受影響。

因此,作爲一個解決方案,我模仿缺乏通過解析主機名java.sun.com到環回接口的IP地址,保證快速的失敗上網。

+0

與此同時,無限連接掛起成爲重定向到錯誤頁面。 – Szocske

+0

+1爲我固定! – kalibrain

2

鏈接斷開你在哪裏得到它的參考,仔細檢查... http ref應該工作,但顯然不是它不存在。

快速谷歌建議有一個glitch in the matrix (oracle servers)

+0

因此,一些隨機的選擇這不是我的錯,它可能會在一段時間內修復? – jack

+0

它或者或者Oracle已經永久地改變/移除了模式定義。他們可能已經移動了它,但我懷疑他們是否會刪除。 – NimChimpsky

1

添加到@ Szocske的答案,休眠似乎想從互聯網上檢索JPA 2.0 XSD,如果它不能識別的版本。

我年長的Hibernate 3.2罐試圖連接到Internet時,我無意間使用了指定的版本與2.0 XSD一個persistence.xml中。所以,如果Hibernate對你來說這樣做,它可能表明你的XML和你的Hibernate jar之間的版本不匹配。

0

至於如果你不想與主機文件一塌糊塗,你可以改變的schemaLocation到類路徑的資源,例如

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee classpath:/com/sun/faces/web-facesconfig_2_0.xsd" 

甚至像

xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com.file.was.not.there.so.changed.so.hibernate.takes.its.own.xsd.from.classpath.or.ignores.the.validation/xml/ns/persistence/orm_2_0.xsd" 
相關問題