论坛首页 Java企业应用论坛

关于java.net.UnknownHostException: hibernate.sourceforge.net

浏览 17941 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2003-09-15  
在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">
就可以了。
   发表时间:2003-09-16  
你们调试程序是否都一直在线的呢?我的意思是说,如果文件头是<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> 的话,如果一断网,程序就会抛出异常说找不到地址hibernate.sourceforge.net,难道一定要DTD引用的吗?
0 请登录后投票
   发表时间:2003-09-16  
肯定是不需要的,因为hibernate2.jar里边已经包括了这个DTD了,Hibernate的XML解析器会首先从CLASSPATH里面load,所以肯定可以load到hibernate2.jar里面的DTD文件,而不需要从网络上load

很可能是你什么地方的CLASSPATH设置的不对,搞的XML解析器找不到本地文件,只能网络上load
0 请登录后投票
   发表时间:2003-09-16  
一语惊醒,不好意思,这么简单的问题,我找到问题所在了。Thanks........
0 请登录后投票
   发表时间:2003-09-16  
找到问题所在,就把解决过程贴出来,好让以后别人碰到问题也知道该怎么办?

不要那么藏私嘛
0 请登录后投票
   发表时间:2003-09-17  
改为

<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

就可以了
0 请登录后投票
   发表时间:2003-09-17  
其实是很低级的错误,因为我在工程里面使用了hibernate的源代码来编译运行,没有导入hibernate的jar,而dtd在jar里面,结果当然找不到了。
0 请登录后投票
   发表时间:2003-09-18  
我的系统现在也是这个样子, 不知道为什么hibernate启动的时候一定要到网络上面去找

但是我的classpath下面是有那两个mapping的啊, 我放在web-inf/classes/下面都不行
1 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics