gpt4 book ai didi

hibernate - 无法读取架构文档'http ://java. sun.com/xml/ns/persistence/persistence_2_0.xsd

转载 作者:行者123 更新时间:2023-12-03 12:25:51 24 4
gpt4 key购买 nike

我正在为大学编写一个简单的 Swing 应用程序,并使用 Hibernate 和 Oracle XE。

我被这个错误困住了:

 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);
}
}

最佳答案

底线:将此行添加到/etc/hosts 文件可以解决此问题:

127.0.0.1 java.sun.com

似乎 Hibernate 将这个和其他“标准”XSD-s 识别为它拥有的东西,并且在没有 Internet 访问权限的情况下使用其内部副本没有问题。

当 XSD 的 HTTP GET 没有成功但也没有失败时,就会出现问题:
返回其他东西或永远响应。
Hibernate 没有为这些情况做好准备。
现在 URL 需要永远响应,并且 Hibernate 没有像今天这样的情况下使用快速超时。

没有 Internet 访问权限的系统不受影响。

因此,作为一种解决方案,我通过将 java.sun.com 主机名解析为环回接口(interface) IP 地址来模拟 Internet 访问不足,从而保证快速失败。

关于hibernate - 无法读取架构文档'http ://java. sun.com/xml/ns/persistence/persistence_2_0.xsd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6519785/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com