why hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net occur?

强颜欢笑 提交于 2019-12-25 01:10:04

问题


org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net

java.net.UnknownHostException: hibernate.sourceforge.net

I'm getting these errors above shown in hibernate and when internet is on then it will work fine. If no internet it will show the above error.

Please help me thanks in advance.

Please give brief and clear explanation.


回答1:


It seems like your DOCTYPE definition in one of your XML files refers to a DTD that is on hibernate.sourceforge.net.

Now that DTD exists but your application cannot access it if it has no access to the internet.

You could try to copy the DTD to a local place and change the header of your XML file from something like this:

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

to something like this:

<!DOCTYPE hibernate-configuration SYSTEM "hibernate-configuration.dtd">  

where "hibernate-configuration.dtd" points to a local resource on your filesystem or in your jar file.

The dirtiest trick to overcome this would be to remove the DTD declaration completely:

<!DOCTYPE hibernate-configuration>

This is also a valid doctype, but the only thing it does is to restrict the name of the root element in the document to "hibernate-configuration". After that it's wildchar.




回答2:


Downloaded the DTD file from here http://hibernate.org/dtd/hibernate-configuration-3.0.dtd

Then add this hibernate-configuration-3.0.dtd file into jar. For maven based project add that file into /src/main/resources folder.

Now in hibernate.cfg.xml add the below DTD declaration

<!DOCTYPE hibernate-configuration SYSTEM "classpath://hibernate-configuration-3.0.dtd">

Now without internet connectivity your app will work.



来源:https://stackoverflow.com/questions/19994796/why-hibernate-sourceforge-net-nested-exception-hibernate-sourceforge-net-occur

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!