Failed to read schema document "http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd

I am writing a simple university Swing application and use Hibernate and Oracle XE.

I am stuck with this 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 a factory entity manager:

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

Bottom line: adding this line to the / etc / hosts file solves the following:

 127.0.0.1 java.sun.com 

It seems that Hibernate recognizes this and other β€œstandard” XSDs as something that it has and does not have problems with its internal copy without Internet access.

Problems arise when the HTTP GET for XSD fails but is not interrupted: Returns something else or requires a response. Sleep mode is not ready for these situations. Right now, the URL is forever responding, and Hibernate does not use a quick timeout, as is necessary for situations like today.

Systems without internet access are not affected.

So, as a solution, I emulate the lack of access to the Internet by resolving the name java.sun.com hostname to the IP address of the loopback interface, guaranteeing a quick failure.

+8
source

the link is missing, where did you get the link for it, double check it ... http should work, but obviously not like it does not exist.

A quick google suggests that there is a glitch in the matrix (oracle servers) .

+2
source

Adding to @Szocske's answer, Hibernate seems to want to get JPA 2.0 xsd from the Internet if it doesn't recognize this version.

My old Hibernate 3.2 jars was trying to connect to the Internet when I accidentally used a persistence.xml file that specified xsd version 2.0. Thus, if Hibernate behaves this way for you, this may indicate a version mismatch between your XML and your sleeping jars.

+1
source

Alternatively, if you do not want to bind to hosts files, you can change the schemaLocation to a class path resource, for example

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

Or even to something random, for example

 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" 
0
source

All Articles