sri
sri

Reputation: 29

Could not parse configuration: hibernate.cfg.xml error

getting the below exception in hibernate

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 com.javatpoint.mypackage.StoreData.main(StoreData.java:13)
Caused by: org.dom4j.DocumentException: Connection refused: connect Nested exception: Connection refused: connect
    at org.dom4j.io.SAXReader.read(SAXReader.java:484)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
    ... 2 more

Hibernate config

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
    <property name="hbm2ddl.auto">create</property> 
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/platinum</property>
    <property name="hibernate.connection.username">admin</property>
    <property name="hibernate.connection.password">admin</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 

    <mapping resource="employee.hbm.xml" />
</session-factory>
</hibernate-configuration>

Any suggestion?

Upvotes: 1

Views: 3289

Answers (2)

Annu Upadhuaya
Annu Upadhuaya

Reputation: 1

In Eclipse Java Project,add hibernate jar file using build path. Add the given following DOCTYPE in the hibernate.cfg.xml(configuration file) Also in the mapping file(save as example.hbm.xml-map class with table in the database) following DOCTYPE

Upvotes: 0

Niraj Gurav
Niraj Gurav

Reputation: 11

This one is a temporary solution. Your Hibernate jars contains dtd for validating your configuration xml. Extract ‘hibernate-configuration-3.0.dtd’ and put it in some directory in your project structure (in this case, I have put it in Project root directory). Add your dtd location to DOCTYPE declaration.

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

It worked for me. It works when system is offline. Fetches DTD from your local system.

Its just that we have to figure a way to fetch dtd from your jar.

you may do it this way :

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

but then, it is throwing

Caused by: org.dom4j.DocumentException: unknown protocol: classpath Nested exception: unknown protocol: classpath

I was getting a Connection Timed Out error. Yours is a Connection Refused Error. Try this in case 'hibernate.org' is refusing connection.

Upvotes: 1

Related Questions