0

<

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

I have this in my hibernate.cfg.xml file. I have the jars downloaded (from http://www.javatpoint.com/src/hb/hibernatejar.zip) in WEB-INF folder in eclipse workspace. Still it says hibernate.sourceforge.net is unreachable. I replaced it with www.hibernate.org/dtd and that is also giving same error. Please help me fix this.

Same issue in mapping file as well.

Error after adding classpath in DOCTYPE:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
    at StoreData.main(StoreData.java:12)
Caused by: org.dom4j.DocumentException: unknown protocol: classpath Nested exception: unknown protocol: classpath
    at org.dom4j.io.SAXReader.read(SAXReader.java:484)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
    ... 2 more
2
  • Are your libraries present in your application classpath? Commented Aug 21, 2014 at 11:18
  • i have added the jars in WEB-INF/lib folder. Apart from that, I added them in java build path also. Commented Aug 21, 2014 at 11:27

2 Answers 2

0

Your DOCTYPE definition refers to a DTD that is on hibernate.sourceforge.net. Now that DTD exists (I can browse it via Firefox) but your application cannot access it. The purpose of the doctype element is to link to a DTD.

Try using below

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"classpath://org/hibernate/hibernate-mapping-3.0.dtd">
Sign up to request clarification or add additional context in comments.

4 Comments

I tried this also. This would mean it will refer from the DTD present in local. But the DTD is present only inside hibernate3.jar in my workspace. How do I point to the DTD inside jar?
@naveenbharadwaj which version of hibernate
I'm not sure. I downloaded the jars from a site. These are the set of jars I have in my workspace. antlr-2.7.6.jar asm-attrs.jar asm.jar c3p0-0.9.1.jar cglib-2.1.3.jar commons-collections-2.1.1.jar commons-logging-1.0.4.jar dom4j-1.6.1.jar ehcache-1.2.3.jar ejb3-persistence.jar hibernate-annotations.jar hibernate-commons-annotations.jar hibernate-validator.jar hibernate3.jar jdbc2_0-stdext.jar jta.jar log4j-1.2.11.jar ojdbc14.jar xerces-2.6.2.jar
I extracted DTD's to a path and referred that in classpath. Now it is giving this error. Caused by: org.dom4j.DocumentException: unknown protocol: classpath Nested exception: unknown protocol: classpath at org.dom4j.io.SAXReader.read(SAXReader.java:484) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481) ... 2 more
0

Following should be your complete DTD in hibernate.cfg.xml file

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

Also do not forget following at the start in the file

<?xml version='1.0' encoding='utf-8'?> 

14 Comments

Can you post full contents of hibernate.cfg.xml?
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "classpath://org/hibernate/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <mapping resource="lang.hbm.xml"/> </session-factory> </hibernate-configuration>
Properties are removed from above comment.
Try following <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <mapping resource="lang.hbm.xml"/> </session-factory> </hibernate-configuration>
here's truncated url "hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" from above string
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.