hibernate.sourceforge.net Nested exception 502 for URL: http://hibernate.sourceforg

在Configuration.buildSessionFactory中,parse  xxx.hbm.xml的时候,经常抛出UnknowHostException:hibernate.sourceforge.net,而我将DTD换成我本地的地址就可以了,难道一定要写上DTD引用的吗?如果我的server没连在internet上面,要把DTD放在本地,但我如果换了路径,那岂不是要将所有的XML都修改? 
异常如下: 
org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net 
at org.dom4j.io.SAXReader.read(SAXReader.java:358) 
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:252) 
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:286) 
at dbdemo.HibernateDemo.run(HibernateDemo.java:53) 
at dbdemo.HibernateDemo.main(HibernateDemo.java:31) 
Nested exception: 
java.net.UnknownHostException: hibernate.sourceforge.net 
at java.net.InetAddress.getAllByName0(InetAddress.java:591) 
at java.net.InetAddress.getAllByName0(InetAddress.java:560) 
at java.net.InetAddress.getByName(InetAddress.java:469) 
at java.net.Socket.<init>(Socket.java:121) 
at sun.net.NetworkClient.doConnect(NetworkClient.java:65) 
at sun.net.www.http.HttpClient.openServer(HttpClient.java:361) 
at sun.net.www.http.HttpClient.openServer(HttpClient.java:548) 
at sun.net.www.http.HttpClient.<init>(HttpClient.java:296) 
at sun.net.www.http.HttpClient.<init>(HttpClient.java:306) 
at sun.net.www.http.HttpClient.New(HttpClient.java:318) 
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:466) 
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:562) 
at java.net.URL.openStream(URL.java:826) 
at org.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityManager.java:748) 
at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:708) 
at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:258) 
at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(XMLDocumentScannerImpl.java:833)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:333)
at org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardParserConfiguration.java:525) 
at org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardParserConfiguration.java:581) 
at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:147) 
at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1158) 
at org.dom4j.io.SAXReader.read(SAXReader.java:339) 
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:252) 
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:286) 
at dbdemo.HibernateDemo.run(HibernateDemo.java:53) 
at dbdemo.HibernateDemo.main(HibernateDemo.java:31) 
MappingException hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net 
java.lang.NullPointerException 
at dbdemo.HibernateDemo.run(HibernateDemo.java:172) 
at dbdemo.HibernateDemo.main(HibernateDemo.java:31) 
Exception in thread "main" 

Users.hbm.xml: 
<?xml version="1.0"?> 

<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> 

<hibernate-mapping> 
    <class 
        name="dbdemo.Users" 
        table="Users" 
        dynamic-update="false" 
    > 

        <id 
            name="userID" 
            column="LogonID" 
            type="string" 
            unsaved-value="any" 
        > 
            <generator class="assigned"> 
            </generator> 
        </id> 

        <property 
            name="emailAddress" 
            type="string" 
            update="true" 
            insert="true" 
            column="EmailAddress" 
        /> 

        <property 
            name="lastLogon" 
            type="date" 
            update="true" 
            insert="true" 
            column="LastLogon" 
        /> 

        <property 
            name="password" 
            type="string" 
            update="true" 
            insert="true" 
            column="Password" 
        /> 

        <property 
            name="userName" 
            type="string" 
            update="true" 
            insert="true" 
            column="Name" 
        /> 

        <set 
            name="contacts" 
            table="Contacts" 
            lazy="false" 
            inverse="false" 
            cascade="all" 
            sort="unsorted" 
        > 

              <key 
                  column="User_ID" 
              /> 

              <one-to-many 
                  class="dbdemo.Contact" 
              /> 
        </set> 

        <set 
            name="books" 
            table="Book_User_Link" 
            lazy="false" 
            inverse="false" 
            cascade="all" 
            sort="unsorted" 
        > 

              <key 
                  column="UserID" 
              /> 

              <many-to-many 
                  class="dbdemo.Book" 
                  column="BookID" 
                  outer-join="auto" 
              /> 

        </set> 

        <one-to-one 
            name="address" 
            class="dbdemo.Address" 
            cascade="none" 
            outer-join="auto" 
            constrained="false" 
        /> 

        <!-- 
            To add non XDoclet property mappings, create a file named 
                hibernate-properties-User.xml 
            containing the additional properties and place it in your merge dir. 
        --> 

    </class> 

</hibernate-mapping> 

如果将文件头换成 

<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN" 
    "file:///F:/hibernate-test/classes/hibernate-mapping-2.0.dtd"> 
就可以了。 

---------------------------------------------------------------------- 

org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net 
at org.dom4j.io.SAXReader.read(SAXReader.java(Compiled Code)) 
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java(Compiled Code)) 
at org.springframework.orm.hibernate.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:383)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:990)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:275)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:193)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java(Compiled Code)) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java(Compiled Code)) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:230)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:304) 
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:80) 
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java(Compiled Code)) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java(Compiled Code)) 
at java.lang.reflect.Constructor.newInstance(Constructor.java(Compiled Code)) 
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:73) 

你可能感兴趣的:(hibernate.sourceforge.net Nested exception 502 for URL: http://hibernate.sourceforg)