本文介绍了无法读取模式文档'http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时删除!!
我遇到了这个错误: $ b $ 我正在为大学编写一个简单的Swing应用程序,并使用Hibernate和Oracle XE。 b
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
29.06.2011 14:54:10 org.hibernate.cfg.Environment buildBytecodeProvider
INFO:字节码提供程序名称:cglib
29.06.2011 14 :54:10 org.hibernate.cfg.Environment< clinit>
INFO:使用JDK 1.4 java.sql.Timestamp处理
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警告
警告:解析XML的警告:XML InputStream( 2)schema_reference.4:无法读取模式文档'http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd',因为1)找不到文档; 2)文件无法阅读; 3)文档的根元素不是< xsd:schema> ;.
29.06.2011 14:54:52 org.hibernate.ejb.packaging.PersistenceXmlLoader $ ErrorLogger警告
我的persistence.xml:
<?xml version =1.0encoding =UTF-8?> ;
< persistence version =2.0xmlns =http://java.sun.com/xml/ns/persistencexmlns:xsi =http://www.w3.org/2001/XMLSchema-实例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>
<属性>
< property name =javax.persistence.jdbc.passwordvalue =AIRPORT/>
< property name =javax.persistence.jdbc.drivervalue =oracle.jdbc.OracleDriver/>
< property name =javax.persistence.jdbc.uservalue =AIRPORT/>
< / properties>
< / persistence-unit>
< /余辉>
创建实体经理工厂:
public static EntityManagerFactory emf;
public static EntityManager em;
static {
try {
emf = Persistence.createEntityManagerFactory(airportPU);
em = emf.createEntityManager();
} catch(Exception e){
System.exit(1);
$ div $解析方案
底部line:将这行添加到/ etc / hosts文件解决了这个问题:
127.0.0.1 java.sun.com
看起来Hibernate会将这个和其他标准XSD-s识别为它的东西,它的内部副本没有互联网访问。
当XSD的HTTP GET不成功时会出现问题,但也不会失败:
返回其他内容或需要永远回应。
Hibernate没有为这些情况做好准备。
现在URL需要永久响应,而Hibernate不会像现在这样应用快速超时。
没有Internet访问的系统不受影响。
所以作为一个解决方案,我通过将java.sun.com主机名解析为回送接口IP地址来模拟缺乏互联网访问,以确保快速失败。
p>
I'm writing a simple Swing app for university and using Hibernate and Oracle XE.
I'm stuck with that error:
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
my 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>
Creating entity manager factory:
public static EntityManagerFactory emf;
public static EntityManager em;
static {
try {
emf = Persistence.createEntityManagerFactory("airportPU");
em = emf.createEntityManager();
} catch (Exception e) {
System.exit(1);
}
}
解决方案
Bottom line: adding this line to the /etc/hosts file solves this:
127.0.0.1 java.sun.com
It seems Hibernate recognizes this and other "standard" XSD-s as something it has, and has no problem working with its internal copy without Internet access.
Problems arise when the HTTP GET for the XSD does not succeed, but does not fail either:Returns something else or takes forever to respond.Hibernate is not prepared for these situations.Right now the URL takes forever to respond, and Hibernate does not employ a quick timeout as it should for situations like today.
Systems without Internet access are unaffected.
So as a solution I am emulating lack of Internet access by resolving the java.sun.com hostname to the loopback interface IP address, guaranteeing a quick failure.
这篇关于无法读取模式文档'http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
1403页,肝出来的..