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.
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.
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.