Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Could not parse configuration: /hibernate.cfg.xml

 
Ankit Jindal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Guys,

I am very new to Hibernate and trying to run very simple program of hibernate.
But I am getting following error (Could not parse configuration:/hibernate.cfg.xml
) error. It seems there is some problem with hibernate.cfg.xml.


Initial SessionFactory creation failed kuch .org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.vaannila.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
at com.vaannila.course.Main.saveCourse(Main.java:22)
at com.vaannila.course.Main.main(Main.java:12)
Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1364)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1298)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1284)
at com.vaannila.util.HibernateUtil.<clinit>(HibernateUtil.java:10)
... 2 more
Caused by: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1354)
... 5 more

Here is my hibernate.cfg.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3//EN" "http://hibernate.sourceforge.net/ hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernateTest</property>
<property name="hibernate.connection.username">root</property>
<property name="show_sql">true</property>
<property name="connection.password">.</property>
<property name="connection.pool_size">10</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="com/vaannila/course/Course.hbm.xml" />
</session-factory>
</hibernate-configuration>
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check you DTD in the second line.
there is a space in this - "http://hibernate.sourceforge.net/ hibernate-configuration-3.0.dtd".Remove the white space.
Always once you have completed the xml file try opening it in IE. You might catch some errors like this.
 
Ankit Jindal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Arun...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic